hackforla / hackforla/peopledepot
GApps script to import db table-descriptions into the audit spreadsheet
- Dominant language
- Python
- Stars
- 14
- Forks
- 37
- Avg merge
- 9d 15h
- Merged PRs (30d)
- 5
Description
### Overview
We need to automate importing the latest table-descriptions from the Django app since it is a repeating process. We should use Apps Script since the audit spreadsheet is on Google spreadsheet.
### Action Items
- [x] have AI generate the script based on the requirements
- [x] run in a document copy, review, make adjustments to the script
- [x] copy code to the real document and run it
- [x] commit the code in the repo
- [x] add some documentation to describe it and on usage
### Resources/Instructions
- [audit spreadsheet](https://docs.google.com/spreadsheets/d/1G9kDheY3MdITZnrthTFIUyprrTEvlMYpkFYWbCAMCmA/edit?gid=2110045944#gid=2110045944) for Django tables
- Extensions > **Apps Script** to see the scripts project
- [table-descriptions.csv](https://github.com/user-attachments/files/26228087/table-descriptions.csv) exported from Django
Requirements from the spreadsheet
```
table-descriptions from the application
spreadsheet
---
Comment in A header:
How this is set up initially
1. export to csv using export-table-descriptions.sh script
2. import as a new sheet
3. add 6 columns to the left and a column after table_name, and copy headers from the other sheet.
4. add formulas to generate Django app name and table_name-prefix columns
5. add formulas to generate Django created columns
6. hide table_name column
7. add filter to Django created column headers and hide TRUE rows for both columns
---
Comment in D header:
Django-created tables can't be audited.
Maybe the TRUE rows should be hidden for visual simplicity.
---
Comment in F header:
These are names of Django apps
All of our tables should be in the "core" app.
The tables in the "project" app should be moved to "core".
---
Comment in G header:
This column comes from the database and is being used to generate the table_name-prefix and django app name columns
---
Comment in H header:
Explanation of table names
1. table names don't have underscores.
ex. Class "CheckType" is table "checktype".
2. Names with underscores are Django-generated xref tables.
ex. "user_practice_area_secondary" is defined as a "practice_area_secondary" ManyToManyField in the "User" model.
```
Some prompts to get started
```
create a google apps script to prompt for a csv file to import, and add it as a new sheet to the current document.
The imported file contains 4 columns: table_name, column_name, data_type, is_nullable.
replace if the same named sheet exists
add to the script
Insert 6 columns to the left: Fields audited, Change title of table, Audit, Django created Table, Django created field, Django app name. Do not do the initial import from column 7, since the insert will move the data over.
Insert a column to the right of table_name and before column_name: table_name-prefix. The values should be '=RIGHT(G269, LEN(G269) - FIND("_", G269))'
make the header text bold
make all header rows into 3 lines to make the columns narrower
format columns A-E into checkboxes
create a custom menu to call it
add to the script
Column F values should use the formula =LEFT(G11, FIND("_", G11) - 1)
Column E values should use the formula =IF(OR(I12="id", I12="uuid", I12="created_at", I12="updated_at"), TRUE, FALSE)
Column D values should be FALSE if Django app name is "core" or "project", otherwise TRUE
add filter to column D to hide if TRUE
hide columns F,G
fill columns D,E,H-K with light gray 2
```
Working code [running in the spreadsheet](https://docs.google.com/spreadsheets/d/1G9kDheY3MdITZnrthTFIUyprrTEvlMYpkFYWbCAMCmA/edit?gid=2110045944#gid=2110045944)
- [Code.js](https://github.com/user-attachments/files/26231145/Code.js)
- [UploadDialog.html](https://github.com/user-attachments/files/26231146/UploadDialog.html)
Contributor guide
Assessment
This issue has not been assessed yet.