supatool 0.3.2 → 0.3.4
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 +12 -0
- package/dist/sync/definitionExtractor.js +41 -19
- package/package.json +1 -1
package/README.md
CHANGED
@@ -285,6 +285,18 @@ supatool extract --all -c "postgresql://..." -o supabase/schemas
|
|
285
285
|
|
286
286
|
## Changelog
|
287
287
|
|
288
|
+
### v0.3.4
|
289
|
+
|
290
|
+
- **FIXED**: Corrected RLS policy to proper format
|
291
|
+
- **FIXED**: Ensured semicolon (;) is properly appended to function definitions
|
292
|
+
- **FIXED**: Removed trailing whitespace from RLS template files
|
293
|
+
|
294
|
+
### v0.3.3
|
295
|
+
|
296
|
+
- **ENHANCED**: Improved SQL comment placement (moved to end of each SQL statement)
|
297
|
+
- **ENHANCED**: Unified comment format for tables, views, functions, and custom types
|
298
|
+
- **FIXED**: Preserved view `security_invoker` settings
|
299
|
+
|
288
300
|
### v0.3.2
|
289
301
|
|
290
302
|
- **ENHANCED**: Adjust for extensions(vector, geometry etc.)
|
@@ -157,11 +157,8 @@ async function fetchRlsPolicies(client, spinner, progress, schemas = ['public'])
|
|
157
157
|
if (Array.isArray(policy.roles)) {
|
158
158
|
roles = policy.roles.join(', ');
|
159
159
|
}
|
160
|
-
else if (typeof policy.roles === 'string') {
|
161
|
-
roles = policy.roles;
|
162
|
-
}
|
163
160
|
else {
|
164
|
-
// PostgreSQLの配列リテラル形式 "{role1,role2}"
|
161
|
+
// PostgreSQLの配列リテラル形式 "{role1,role2}" または単純な文字列を処理
|
165
162
|
roles = String(policy.roles)
|
166
163
|
.replace(/[{}]/g, '') // 中括弧を除去
|
167
164
|
.replace(/"/g, ''); // ダブルクォートを除去
|
@@ -230,14 +227,23 @@ async function fetchFunctions(client, spinner, progress, schemas = ['public']) {
|
|
230
227
|
let ddl = '';
|
231
228
|
if (!row.comment) {
|
232
229
|
ddl += `-- Function: ${functionSignature}\n`;
|
233
|
-
ddl += `-- COMMENT ON FUNCTION ${functionSignature} IS '_your_comment_here_';\n\n`;
|
234
230
|
}
|
235
231
|
else {
|
236
232
|
ddl += `-- ${row.comment}\n`;
|
233
|
+
}
|
234
|
+
// 関数定義を追加(セミコロンを確実に付与)
|
235
|
+
let functionDef = row.definition;
|
236
|
+
if (!functionDef.trim().endsWith(';')) {
|
237
|
+
functionDef += ';';
|
238
|
+
}
|
239
|
+
ddl += functionDef + '\n\n';
|
240
|
+
// COMMENT ON文を追加
|
241
|
+
if (!row.comment) {
|
242
|
+
ddl += `-- COMMENT ON FUNCTION ${functionSignature} IS '_your_comment_here_';\n\n`;
|
243
|
+
}
|
244
|
+
else {
|
237
245
|
ddl += `COMMENT ON FUNCTION ${functionSignature} IS '${row.comment}';\n\n`;
|
238
246
|
}
|
239
|
-
// 関数定義を追加
|
240
|
-
ddl += row.definition;
|
241
247
|
functions.push({
|
242
248
|
name: row.name,
|
243
249
|
type: 'function',
|
@@ -469,17 +475,23 @@ async function fetchCustomTypes(client, spinner, progress, schemas = ['public'])
|
|
469
475
|
}
|
470
476
|
}
|
471
477
|
if (ddl) {
|
472
|
-
//
|
478
|
+
// 型コメントを先頭に追加
|
473
479
|
let finalDdl = '';
|
474
480
|
if (!row.comment) {
|
475
481
|
finalDdl += `-- Type: ${row.type_name}\n`;
|
476
|
-
finalDdl += `-- COMMENT ON TYPE ${row.schema_name}.${row.type_name} IS '_your_comment_here_';\n\n`;
|
477
482
|
}
|
478
483
|
else {
|
479
484
|
finalDdl += `-- ${row.comment}\n`;
|
485
|
+
}
|
486
|
+
// 型定義を追加
|
487
|
+
finalDdl += ddl + '\n\n';
|
488
|
+
// COMMENT ON文を追加
|
489
|
+
if (!row.comment) {
|
490
|
+
finalDdl += `-- COMMENT ON TYPE ${row.schema_name}.${row.type_name} IS '_your_comment_here_';\n\n`;
|
491
|
+
}
|
492
|
+
else {
|
480
493
|
finalDdl += `COMMENT ON TYPE ${row.schema_name}.${row.type_name} IS '${row.comment}';\n\n`;
|
481
494
|
}
|
482
|
-
finalDdl += ddl;
|
483
495
|
types.push({
|
484
496
|
name: `${row.schema_name}_${row.type_name}`,
|
485
497
|
type: 'type',
|
@@ -608,12 +620,11 @@ async function fetchTableDefinitions(client, spinner, progress, schemas = ['publ
|
|
608
620
|
if (viewCommentResult.rows.length > 0 && viewCommentResult.rows[0].view_comment) {
|
609
621
|
comment = viewCommentResult.rows[0].view_comment;
|
610
622
|
ddl = `-- ${comment}\n`;
|
611
|
-
ddl += `COMMENT ON VIEW ${schemaName}.${name} IS '${comment}';\n\n`;
|
612
623
|
}
|
613
624
|
else {
|
614
625
|
ddl = `-- View: ${name}\n`;
|
615
|
-
ddl += `-- COMMENT ON VIEW ${schemaName}.${name} IS '_your_comment_here_';\n\n`;
|
616
626
|
}
|
627
|
+
// ビュー定義を追加
|
617
628
|
let ddlStart = `CREATE OR REPLACE VIEW ${name}`;
|
618
629
|
// security_invoker設定をチェック
|
619
630
|
if (view.reloptions) {
|
@@ -630,7 +641,14 @@ async function fetchTableDefinitions(client, spinner, progress, schemas = ['publ
|
|
630
641
|
}
|
631
642
|
}
|
632
643
|
}
|
633
|
-
ddl +=
|
644
|
+
ddl += ddlStart + ' AS\n' + view.definition + ';\n\n';
|
645
|
+
// COMMENT ON文を追加
|
646
|
+
if (viewCommentResult.rows.length > 0 && viewCommentResult.rows[0].view_comment) {
|
647
|
+
ddl += `COMMENT ON VIEW ${schemaName}.${name} IS '${comment}';\n\n`;
|
648
|
+
}
|
649
|
+
else {
|
650
|
+
ddl += `-- COMMENT ON VIEW ${schemaName}.${name} IS '_your_comment_here_';\n\n`;
|
651
|
+
}
|
634
652
|
// ビューの作成時刻を取得(可能であれば)
|
635
653
|
try {
|
636
654
|
const viewStatsResult = await client.query(`
|
@@ -652,8 +670,7 @@ async function fetchTableDefinitions(client, spinner, progress, schemas = ['publ
|
|
652
670
|
}
|
653
671
|
}
|
654
672
|
catch (error) {
|
655
|
-
|
656
|
-
return null;
|
673
|
+
// エラーの場合はコメントなし
|
657
674
|
}
|
658
675
|
}
|
659
676
|
return {
|
@@ -810,13 +827,12 @@ async function generateCreateTableDDL(client, tableName, schemaName = 'public')
|
|
810
827
|
});
|
811
828
|
// テーブルコメントを先頭に追加(スキーマ名を含む)
|
812
829
|
let ddl = '';
|
830
|
+
// テーブルコメントを先頭に追加
|
813
831
|
if (tableCommentResult.rows.length > 0 && tableCommentResult.rows[0].table_comment) {
|
814
832
|
ddl += `-- ${tableCommentResult.rows[0].table_comment}\n`;
|
815
|
-
ddl += `COMMENT ON TABLE ${schemaName}.${tableName} IS '${tableCommentResult.rows[0].table_comment}';\n\n`;
|
816
833
|
}
|
817
834
|
else {
|
818
835
|
ddl += `-- Table: ${tableName}\n`;
|
819
|
-
ddl += `-- COMMENT ON TABLE ${schemaName}.${tableName} IS '_your_comment_here_';\n\n`;
|
820
836
|
}
|
821
837
|
// CREATE TABLE文を生成
|
822
838
|
ddl += `CREATE TABLE IF NOT EXISTS ${tableName} (\n`;
|
@@ -853,8 +869,14 @@ async function generateCreateTableDDL(client, tableName, schemaName = 'public')
|
|
853
869
|
for (const fk of foreignKeyResult.rows) {
|
854
870
|
ddl += `,\n CONSTRAINT ${fk.constraint_name} FOREIGN KEY (${fk.columns}) REFERENCES ${fk.foreign_table_schema}.${fk.foreign_table_name} (${fk.foreign_columns})`;
|
855
871
|
}
|
856
|
-
ddl += '\n);\n';
|
857
|
-
|
872
|
+
ddl += '\n);\n\n';
|
873
|
+
// COMMENT ON文を追加
|
874
|
+
if (tableCommentResult.rows.length > 0 && tableCommentResult.rows[0].table_comment) {
|
875
|
+
ddl += `COMMENT ON TABLE ${schemaName}.${tableName} IS '${tableCommentResult.rows[0].table_comment}';\n\n`;
|
876
|
+
}
|
877
|
+
else {
|
878
|
+
ddl += `-- COMMENT ON TABLE ${schemaName}.${tableName} IS '_your_comment_here_';\n\n`;
|
879
|
+
}
|
858
880
|
// カラムコメントを追加(スキーマ名を含む)
|
859
881
|
if (columnComments.size > 0) {
|
860
882
|
ddl += '\n-- カラムコメント\n';
|
package/package.json
CHANGED