spine-framework 0.2.6 → 0.2.7
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.
|
@@ -99,52 +99,35 @@ async function migrateCommand(options: MigrateOptions): Promise<void> {
|
|
|
99
99
|
// Dollar-quoted strings ($$ ... $$ or $tag$ ... $tag$) can contain semicolons
|
|
100
100
|
// that are NOT statement terminators.
|
|
101
101
|
function splitSqlStatements(sql: string): string[] {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
let
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
// Check for end of dollar quote
|
|
132
|
-
if (sql.slice(i, i + dollarTag.length) === dollarTag) {
|
|
133
|
-
inDollarQuote = false
|
|
134
|
-
current += dollarTag
|
|
135
|
-
i += dollarTag.length
|
|
136
|
-
continue
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
current += sql[i]
|
|
140
|
-
i++
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Don't forget the last statement (might not have trailing semicolon)
|
|
144
|
-
const last = current.trim()
|
|
145
|
-
if (last.length > 0 && !last.startsWith('--')) {
|
|
146
|
-
statements.push(last + (last.endsWith(';') ? '' : ';'))
|
|
147
|
-
}
|
|
102
|
+
// Simple approach: use regex to split, but protect dollar-quoted blocks first
|
|
103
|
+
// Replace dollar-quoted blocks with placeholders, split by semicolons, then restore
|
|
104
|
+
|
|
105
|
+
const dollarBlocks: string[] = []
|
|
106
|
+
let blockIndex = 0
|
|
107
|
+
|
|
108
|
+
// Extract dollar-quoted blocks and replace with placeholders
|
|
109
|
+
const protectedSql = sql.replace(/\$[A-Za-z_]*\$[\s\S]*?\$[A-Za-z_]*\$/g, (match) => {
|
|
110
|
+
const placeholder = `__DOLLAR_BLOCK_${blockIndex}__`
|
|
111
|
+
dollarBlocks[blockIndex] = match
|
|
112
|
+
blockIndex++
|
|
113
|
+
return placeholder
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
// Split by semicolons
|
|
117
|
+
const rawStatements = protectedSql.split(';')
|
|
118
|
+
|
|
119
|
+
// Restore dollar blocks and filter
|
|
120
|
+
const statements = rawStatements
|
|
121
|
+
.map(s => {
|
|
122
|
+
let restored = s.trim()
|
|
123
|
+
// Restore dollar blocks
|
|
124
|
+
dollarBlocks.forEach((block, idx) => {
|
|
125
|
+
restored = restored.replace(`__DOLLAR_BLOCK_${idx}__`, block)
|
|
126
|
+
})
|
|
127
|
+
return restored
|
|
128
|
+
})
|
|
129
|
+
.filter(s => s.length > 0 && !s.startsWith('--'))
|
|
130
|
+
.map(s => s + ';')
|
|
148
131
|
|
|
149
132
|
return statements
|
|
150
133
|
}
|
|
@@ -152,11 +135,7 @@ async function migrateCommand(options: MigrateOptions): Promise<void> {
|
|
|
152
135
|
const statements = splitSqlStatements(sql)
|
|
153
136
|
|
|
154
137
|
try {
|
|
155
|
-
for (
|
|
156
|
-
const stmt = statements[i]
|
|
157
|
-
if (process.env.SPINE_DEBUG_MIGRATE) {
|
|
158
|
-
console.log(`\n [${i + 1}/${statements.length}] ${stmt.substring(0, 60).replace(/\n/g, ' ')}...`)
|
|
159
|
-
}
|
|
138
|
+
for (const stmt of statements) {
|
|
160
139
|
await client.query(stmt)
|
|
161
140
|
}
|
|
162
141
|
console.log('✓')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../../.framework/cli/commands/migrate.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../../.framework/cli/commands/migrate.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAiJxC,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,QAevD"}
|