supatool 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/sync/definitionExtractor.js +36 -15
- package/package.json +1 -1
package/README.md
CHANGED
@@ -285,6 +285,12 @@ supatool extract --all -c "postgresql://..." -o supabase/schemas
|
|
285
285
|
|
286
286
|
## Changelog
|
287
287
|
|
288
|
+
### v0.3.3
|
289
|
+
|
290
|
+
- **ENHANCED**: Improved SQL comment placement (moved to end of each SQL statement)
|
291
|
+
- **ENHANCED**: Unified comment format for tables, views, functions, and custom types
|
292
|
+
- **FIXED**: Preserved view `security_invoker` settings
|
293
|
+
|
288
294
|
### v0.3.2
|
289
295
|
|
290
296
|
- **ENHANCED**: Adjust for extensions(vector, geometry etc.)
|
@@ -230,14 +230,19 @@ async function fetchFunctions(client, spinner, progress, schemas = ['public']) {
|
|
230
230
|
let ddl = '';
|
231
231
|
if (!row.comment) {
|
232
232
|
ddl += `-- Function: ${functionSignature}\n`;
|
233
|
-
ddl += `-- COMMENT ON FUNCTION ${functionSignature} IS '_your_comment_here_';\n\n`;
|
234
233
|
}
|
235
234
|
else {
|
236
235
|
ddl += `-- ${row.comment}\n`;
|
237
|
-
ddl += `COMMENT ON FUNCTION ${functionSignature} IS '${row.comment}';\n\n`;
|
238
236
|
}
|
239
237
|
// 関数定義を追加
|
240
|
-
ddl += row.definition;
|
238
|
+
ddl += row.definition + '\n\n';
|
239
|
+
// COMMENT ON文を追加
|
240
|
+
if (!row.comment) {
|
241
|
+
ddl += `-- COMMENT ON FUNCTION ${functionSignature} IS '_your_comment_here_';\n\n`;
|
242
|
+
}
|
243
|
+
else {
|
244
|
+
ddl += `COMMENT ON FUNCTION ${functionSignature} IS '${row.comment}';\n\n`;
|
245
|
+
}
|
241
246
|
functions.push({
|
242
247
|
name: row.name,
|
243
248
|
type: 'function',
|
@@ -469,17 +474,23 @@ async function fetchCustomTypes(client, spinner, progress, schemas = ['public'])
|
|
469
474
|
}
|
470
475
|
}
|
471
476
|
if (ddl) {
|
472
|
-
//
|
477
|
+
// 型コメントを先頭に追加
|
473
478
|
let finalDdl = '';
|
474
479
|
if (!row.comment) {
|
475
480
|
finalDdl += `-- Type: ${row.type_name}\n`;
|
476
|
-
finalDdl += `-- COMMENT ON TYPE ${row.schema_name}.${row.type_name} IS '_your_comment_here_';\n\n`;
|
477
481
|
}
|
478
482
|
else {
|
479
483
|
finalDdl += `-- ${row.comment}\n`;
|
484
|
+
}
|
485
|
+
// 型定義を追加
|
486
|
+
finalDdl += ddl + '\n\n';
|
487
|
+
// COMMENT ON文を追加
|
488
|
+
if (!row.comment) {
|
489
|
+
finalDdl += `-- COMMENT ON TYPE ${row.schema_name}.${row.type_name} IS '_your_comment_here_';\n\n`;
|
490
|
+
}
|
491
|
+
else {
|
480
492
|
finalDdl += `COMMENT ON TYPE ${row.schema_name}.${row.type_name} IS '${row.comment}';\n\n`;
|
481
493
|
}
|
482
|
-
finalDdl += ddl;
|
483
494
|
types.push({
|
484
495
|
name: `${row.schema_name}_${row.type_name}`,
|
485
496
|
type: 'type',
|
@@ -608,12 +619,11 @@ async function fetchTableDefinitions(client, spinner, progress, schemas = ['publ
|
|
608
619
|
if (viewCommentResult.rows.length > 0 && viewCommentResult.rows[0].view_comment) {
|
609
620
|
comment = viewCommentResult.rows[0].view_comment;
|
610
621
|
ddl = `-- ${comment}\n`;
|
611
|
-
ddl += `COMMENT ON VIEW ${schemaName}.${name} IS '${comment}';\n\n`;
|
612
622
|
}
|
613
623
|
else {
|
614
624
|
ddl = `-- View: ${name}\n`;
|
615
|
-
ddl += `-- COMMENT ON VIEW ${schemaName}.${name} IS '_your_comment_here_';\n\n`;
|
616
625
|
}
|
626
|
+
// ビュー定義を追加
|
617
627
|
let ddlStart = `CREATE OR REPLACE VIEW ${name}`;
|
618
628
|
// security_invoker設定をチェック
|
619
629
|
if (view.reloptions) {
|
@@ -630,7 +640,14 @@ async function fetchTableDefinitions(client, spinner, progress, schemas = ['publ
|
|
630
640
|
}
|
631
641
|
}
|
632
642
|
}
|
633
|
-
ddl +=
|
643
|
+
ddl += ddlStart + ' AS\n' + view.definition + ';\n\n';
|
644
|
+
// COMMENT ON文を追加
|
645
|
+
if (viewCommentResult.rows.length > 0 && viewCommentResult.rows[0].view_comment) {
|
646
|
+
ddl += `COMMENT ON VIEW ${schemaName}.${name} IS '${comment}';\n\n`;
|
647
|
+
}
|
648
|
+
else {
|
649
|
+
ddl += `-- COMMENT ON VIEW ${schemaName}.${name} IS '_your_comment_here_';\n\n`;
|
650
|
+
}
|
634
651
|
// ビューの作成時刻を取得(可能であれば)
|
635
652
|
try {
|
636
653
|
const viewStatsResult = await client.query(`
|
@@ -652,8 +669,7 @@ async function fetchTableDefinitions(client, spinner, progress, schemas = ['publ
|
|
652
669
|
}
|
653
670
|
}
|
654
671
|
catch (error) {
|
655
|
-
|
656
|
-
return null;
|
672
|
+
// エラーの場合はコメントなし
|
657
673
|
}
|
658
674
|
}
|
659
675
|
return {
|
@@ -810,13 +826,12 @@ async function generateCreateTableDDL(client, tableName, schemaName = 'public')
|
|
810
826
|
});
|
811
827
|
// テーブルコメントを先頭に追加(スキーマ名を含む)
|
812
828
|
let ddl = '';
|
829
|
+
// テーブルコメントを先頭に追加
|
813
830
|
if (tableCommentResult.rows.length > 0 && tableCommentResult.rows[0].table_comment) {
|
814
831
|
ddl += `-- ${tableCommentResult.rows[0].table_comment}\n`;
|
815
|
-
ddl += `COMMENT ON TABLE ${schemaName}.${tableName} IS '${tableCommentResult.rows[0].table_comment}';\n\n`;
|
816
832
|
}
|
817
833
|
else {
|
818
834
|
ddl += `-- Table: ${tableName}\n`;
|
819
|
-
ddl += `-- COMMENT ON TABLE ${schemaName}.${tableName} IS '_your_comment_here_';\n\n`;
|
820
835
|
}
|
821
836
|
// CREATE TABLE文を生成
|
822
837
|
ddl += `CREATE TABLE IF NOT EXISTS ${tableName} (\n`;
|
@@ -853,8 +868,14 @@ async function generateCreateTableDDL(client, tableName, schemaName = 'public')
|
|
853
868
|
for (const fk of foreignKeyResult.rows) {
|
854
869
|
ddl += `,\n CONSTRAINT ${fk.constraint_name} FOREIGN KEY (${fk.columns}) REFERENCES ${fk.foreign_table_schema}.${fk.foreign_table_name} (${fk.foreign_columns})`;
|
855
870
|
}
|
856
|
-
ddl += '\n);\n';
|
857
|
-
|
871
|
+
ddl += '\n);\n\n';
|
872
|
+
// COMMENT ON文を追加
|
873
|
+
if (tableCommentResult.rows.length > 0 && tableCommentResult.rows[0].table_comment) {
|
874
|
+
ddl += `COMMENT ON TABLE ${schemaName}.${tableName} IS '${tableCommentResult.rows[0].table_comment}';\n\n`;
|
875
|
+
}
|
876
|
+
else {
|
877
|
+
ddl += `-- COMMENT ON TABLE ${schemaName}.${tableName} IS '_your_comment_here_';\n\n`;
|
878
|
+
}
|
858
879
|
// カラムコメントを追加(スキーマ名を含む)
|
859
880
|
if (columnComments.size > 0) {
|
860
881
|
ddl += '\n-- カラムコメント\n';
|
package/package.json
CHANGED