@powerhousedao/network-admin 0.0.31 → 0.0.32
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../../processors/workstreams/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAGrE,wBAAsB,EAAE,CAAC,EAAE,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../../processors/workstreams/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAGrE,wBAAsB,EAAE,CAAC,EAAE,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CA2F9D;AAED,wBAAsB,IAAI,CAAC,EAAE,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAOhE"}
|
|
@@ -14,6 +14,7 @@ export async function up(db) {
|
|
|
14
14
|
// Type might already exist, ignore error
|
|
15
15
|
}
|
|
16
16
|
// Create table with IF NOT EXISTS
|
|
17
|
+
let tableCreated = false;
|
|
17
18
|
try {
|
|
18
19
|
await db.schema
|
|
19
20
|
.createTable("workstreams")
|
|
@@ -31,46 +32,66 @@ export async function up(db) {
|
|
|
31
32
|
.addPrimaryKeyConstraint("workstreams_pkey", ["workstream_phid"])
|
|
32
33
|
.ifNotExists()
|
|
33
34
|
.execute();
|
|
35
|
+
tableCreated = true;
|
|
34
36
|
}
|
|
35
37
|
catch (error) {
|
|
36
|
-
// Table might already exist
|
|
38
|
+
// Table creation failed, might already exist or error occurred
|
|
39
|
+
// Check if table exists before trying to add columns
|
|
37
40
|
}
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
// Check if table exists before trying to add columns
|
|
42
|
+
let tableExists = false;
|
|
43
|
+
try {
|
|
44
|
+
const result = await sql `
|
|
45
|
+
SELECT EXISTS (
|
|
46
|
+
SELECT FROM information_schema.tables
|
|
47
|
+
WHERE table_name = 'workstreams'
|
|
48
|
+
)
|
|
49
|
+
`.execute(db);
|
|
50
|
+
tableExists = result.rows?.[0]?.exists === true || result[0]?.exists === true;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
// If we can't check, assume table doesn't exist
|
|
54
|
+
tableExists = false;
|
|
55
|
+
}
|
|
56
|
+
// Only try to add columns if table exists and wasn't just created
|
|
57
|
+
if (tableExists && !tableCreated) {
|
|
58
|
+
// Add missing columns if table already existed (migration upgrade path)
|
|
59
|
+
// Use try-catch since PostgreSQL doesn't support IF NOT EXISTS for ALTER TABLE ADD COLUMN
|
|
60
|
+
const addColumnIfNotExists = async (columnName, columnDef) => {
|
|
61
|
+
try {
|
|
62
|
+
if (typeof columnDef === 'string') {
|
|
63
|
+
await db.schema.alterTable("workstreams").addColumn(columnName, columnDef).execute();
|
|
49
64
|
}
|
|
50
|
-
else
|
|
51
|
-
|
|
65
|
+
else {
|
|
66
|
+
// For enum types (sql template), use ALTER TABLE with raw SQL
|
|
67
|
+
if (columnName === 'workstream_status') {
|
|
68
|
+
await sql `ALTER TABLE workstreams ADD COLUMN workstream_status workstream_status`.execute(db);
|
|
69
|
+
}
|
|
70
|
+
else if (columnName === 'initial_proposal_status') {
|
|
71
|
+
await sql `ALTER TABLE workstreams ADD COLUMN initial_proposal_status proposal_status`.execute(db);
|
|
72
|
+
}
|
|
52
73
|
}
|
|
53
74
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
75
|
+
catch (error) {
|
|
76
|
+
// Column already exists (error code 42701) - ignore
|
|
77
|
+
// Table doesn't exist (error code 42P01) - ignore (shouldn't happen but handle gracefully)
|
|
78
|
+
if (error?.code !== '42701' && error?.code !== '42P16' && error?.code !== '42P01') {
|
|
79
|
+
console.warn(`Error adding column ${columnName}:`, error?.message || error);
|
|
80
|
+
}
|
|
60
81
|
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
82
|
+
};
|
|
83
|
+
await addColumnIfNotExists('network_phid', 'varchar(255)');
|
|
84
|
+
await addColumnIfNotExists('network_slug', 'varchar(255)');
|
|
85
|
+
await addColumnIfNotExists('workstream_phid', 'varchar(255)');
|
|
86
|
+
await addColumnIfNotExists('workstream_slug', 'varchar(255)');
|
|
87
|
+
await addColumnIfNotExists('workstream_title', 'varchar(255)');
|
|
88
|
+
await addColumnIfNotExists('workstream_status', sql `workstream_status`);
|
|
89
|
+
await addColumnIfNotExists('sow_phid', 'varchar(255)');
|
|
90
|
+
await addColumnIfNotExists('roadmap_oid', 'varchar(255)');
|
|
91
|
+
await addColumnIfNotExists('final_milestone_target', 'timestamp');
|
|
92
|
+
await addColumnIfNotExists('initial_proposal_status', sql `proposal_status`);
|
|
93
|
+
await addColumnIfNotExists('initial_proposal_author', 'varchar(255)');
|
|
94
|
+
}
|
|
74
95
|
}
|
|
75
96
|
export async function down(db) {
|
|
76
97
|
// drop table
|