import_users.js generates invalid SQL resulting in an error
Opened this issue · 1 comments
evelant commented
Bug report
Per title, import_users.js generates invalid SQL.
To Reproduce
- Export with firestoreusers2json.js (after fixing the batching bug that generates invalid data if you have more than 1 batch).
- Attempt to import generated JSON
node import_users.js ./users.json
- Observe error
loading users from ./users.json
insertUsers: 100
runSQL error: error: syntax error at or near "s"
at Parser.parseErrorMessage (/Users/imagio/dev/firebase-to-supabase/node_modules/pg-protocol/dist/parser.js:287:98)
at Parser.handlePacket (/Users/imagio/dev/firebase-to-supabase/node_modules/pg-protocol/dist/parser.js:126:29)
at Parser.parse (/Users/imagio/dev/firebase-to-supabase/node_modules/pg-protocol/dist/parser.js:39:38)
at Socket.<anonymous> (/Users/imagio/dev/firebase-to-supabase/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Socket.Readable.push (node:internal/streams/readable:228:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
length: 94,
severity: 'ERROR',
code: '42601',
detail: undefined,
hint: undefined,
position: '150346',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'scan.l',
line: '1188',
routine: 'scanner_yyerror'
}
sql was:
......many thousands of lines of SQL
Expected behavior
Import works or at least fails with a useful error message
Screenshots
If applicable, add screenshots to help explain your problem.
System information
- OS: macos
- Browser: N/A
- Version of supabase-js: N/A
- Version of Node.js: 16.19.0
Additional context
evelant commented
Ah I think I see. The input is not sanitized. If it contains a '
(single quote) then invalid SQL is generated at JSON.stringify(user)
... It needs to be JSON.stringify(user).replace(/'/g, "''")