Skip to content

Commit

Permalink
Add table description, column description and isarray
Browse files Browse the repository at this point in the history
  • Loading branch information
aloccid-iata authored Apr 30, 2024
1 parent 32bc6db commit 3bf2e8f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
24 changes: 17 additions & 7 deletions bin/import
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,29 @@ const importTablePositions = async (databaseName, tables) => {
await fs.writeFile(`src/config/databases/${databaseName}/tablePositions.json`, JSON.stringify(tablePositions, null, 2), "utf8");
};

const importTableConfigs = async (databaseName, tables) => {
const importTableConfigs = async (databaseName, tables, tablesDescription) => {
await fs.mkdir(`src/config/databases/${databaseName}/tables`);

Object.keys(tables).forEach(async tableName => {
const tableFile = `src/config/databases/${databaseName}/tables/${tableName}.json`;
const tableConfig = {
name: tableName,
description: "",
description: tablesDescription[tableName][0],
schemaColor: "#91C4F2",
columns: []
};

tables[tableName].forEach(row => {
const columnName = row[0];
const columnType = row[1];
const propertyDescription = row[2];
const is_array = row[3];

tableConfig.columns.push({
name: columnName,
description: "",
type: columnType
description: propertyDescription,
type: columnType,
array : is_array
});
});

Expand Down Expand Up @@ -146,6 +149,7 @@ const importConfigFiles = async ({ databaseName }) => {

const tableData = await readTableData(databaseName);
const tables = {};
const tablesDescription = {};
const schemas = {};

tableData.forEach(row => {
Expand All @@ -154,15 +158,21 @@ const importConfigFiles = async ({ databaseName }) => {
const name = row.table_schema === "public" ? row.table_name : `${row.table_schema}.${row.table_name}`;

if(tables[name]) {
tables[name].push([row.column_name, row.data_type]);
tables[name].push([row.column_name, row.data_type, row.property_description, row.is_array]);
} else {
tables[name] = [[row.column_name, row.data_type]];
tables[name] = [[row.column_name, row.data_type, row.property_description, row.is_array]];
}

if(tablesDescription[name]) {
tablesDescription[name].push([row.table_description]);
} else {
tablesDescription[name] = [[row.table_description]];
}
});

await importSchemaColors(databaseName, schemas);
await importTablePositions(databaseName, tables);
await importTableConfigs(databaseName, tables);
await importTableConfigs(databaseName, tables, tablesDescription);
await importEdgeConfigs(databaseName, tables);
await importTablesIndexFile(databaseName, tables);
await addDatabaseEntry(databaseName);
Expand Down
2 changes: 1 addition & 1 deletion schema.csv.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"table_schema","table_name","column_name","data_type","ordinal_position"
"table_schema","table_name","column_name","data_type","ordinal_position","table_description","property_description","is_array"
"adjust","callbacks","id","bigint",1
"adjust","callbacks","tracker","character varying",2
"adjust","callbacks","created_at","timestamp without time zone",3
Expand Down

0 comments on commit 3bf2e8f

Please sign in to comment.