Skip to content

GApps script to import db table-descriptions into the audit spreadsheet #655

Description

@fyliu

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

  • have AI generate the script based on the requirements
  • run in a document copy, review, make adjustments to the script
  • copy code to the real document and run it
  • commit the code in the repo
  • add some documentation to describe it and on usage

Resources/Instructions

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

Metadata

Metadata

Assignees

Labels

PII: FALSETable or function does not have or use Personally Identifiable Information (PII)complexity: smallSmall changes with all steps laid out in detailfeature: process improvementrole: back ends: PD teamstakeholder: People Depot Teamsize: 2ptCan be done in 7-12 hours

Type

Fields

No fields configured for Task.

Projects

Status
🏗In progress-actively working

Relationships

None yet

Development

No branches or pull requests

Issue actions