Comments (7)
I found a temporary solution, I've commented out the batching in jsonStream.on("data":
// if (insertRows.length >= 100) {
// // BATCH_SIZE
// const result = await runSQL(makeInsertStatement(fields, insertRows));
// insertRows = [];
// }
The issue being that the same code is being launched in jsonStream.on("end":
jsonStream.on("end", async () => {
const result = await runSQL(makeInsertStatement(fields, insertRows));
resolve("DONE");
});
So somehow as the insertRows[] gets emptied, it gets filled with the same data and gets sent again in a new batch until 100 times (?) later.
Worth looking further to help the community, I didn't pinpoint the root cause, probably something related to async code.
from firebase-to-supabase.
I've played around and managed to get an error message that could help pin point the area of problem:
runSQL error: error: duplicate key value violates unique constraint "users_uid_key"
at Parser.parseErrorMessage (C:\Users\User\Documents\Code\fb2sb\firebase-to-supabase\node_modules\pg-protocol\dist\parser.js:287:98)
at Parser.handlePacket (C:\Users\User\Documents\Code\fb2sb\firebase-to-supabase\node_modules\pg-protocol\dist\parser.js:126:29)
at Parser.parse (C:\Users\User\Documents\Code\fb2sb\firebase-to-supabase\node_modules\pg-protocol\dist\parser.js:39:38)
at Socket.<anonymous> (C:\Users\User\Documents\Code\fb2sb\firebase-to-supabase\node_modules\pg-protocol\dist\index.js:11:42)
at Socket.emit (node:events:390: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:199:23) {
length: 214,
severity: 'ERROR',
code: '23505',
detail: 'Key (uid)=(04Ep1qjsohdFua9ANBrtVpveB152) already exists.',
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: 'public',
table: 'users',
column: undefined,
dataType: undefined,
constraint: 'users_uid_key',
file: 'nbtinsert.c',
line: '664',
routine: '_bt_check_unique'
}
sql was: insert into "users" ("uid","username","phone","email","account_status","is_premium","is_visible","number_of_swipes_today","is_tuto_seen","is_account_created","push_token") values (
from firebase-to-supabase.
I found a temporary solution, I've commented out the batching in jsonStream.on("data":
// if (insertRows.length >= 100) { // // BATCH_SIZE // const result = await runSQL(makeInsertStatement(fields, insertRows)); // insertRows = []; // }
The issue being that the same code is being launched in jsonStream.on("end":
jsonStream.on("end", async () => { const result = await runSQL(makeInsertStatement(fields, insertRows)); resolve("DONE"); });
So somehow as the insertRows[] gets emptied, it gets filled with the same data and gets sent again in a new batch until 100 times (?) later.
Worth looking further to help the community, I didn't pinpoint the root cause, probably something related to async code.
Had the same problem , You saved my Life
from firebase-to-supabase.
@spotvin42 hi mate. Thank you for reporting this issue. I'm also encountering the same problem :)
I'm trying to migrate a Firestore collection Users
to Supabase and rename then this to the profiles
table, but instead of ~1250 records Supabase creates and dublicates around ~220000 for some reason :)
Coometing hasn't helped so far and I've been using these commands within firestore directory.
Dump Firestore collection to JSON file:
node firestore2json.js Users 1000 0
Import JSON file to Supabase (PostgreSQL)
node json2supabase.js ./Users.json uuid id
from firebase-to-supabase.
@burggraf could you please look at it?
from firebase-to-supabase.
I believe the issue here is that the callback function provided to on
is flagged as async
, but EventEmitter
in Node processes events synchronously and will ignore the return value of the callback function (in this case a Promise that we want to await
). So insertRows
is not getting cleared as we would expect after each batch, because Node isn't waiting for that database operation to complete (and the call to set insertRows = []
effectively gets orphaned in its own thread).
The solution offered by @spotvin42 works by virtue of collecting every into a single array before processing all at once at the end once the stream has finished parsing. However, this has potential to cause performance/memory issues in the case of very large collections.
An alternative which also avoids the problem of processing all records in a single batch is simply to remove the async/await
from the callback function entirely.
if (insertRows.length >= 100) { // BATCH_SIZE
runSQL(makeInsertStatement(fields, insertRows));
insertRows = [];
}
In practice it'd probably be better to open a database transaction and then commit in the jsonStream.on('end')
callback, but hopefully this helps give a bit more context to the issue.
from firebase-to-supabase.
Related Issues (14)
- add missing setup steps HOT 2
- How to get firestore subcollections for migration? HOT 2
- firestoreusers2json creates invalid json HOT 1
- import_users.js generates invalid SQL resulting in an error HOT 1
- Firebase auth import does not preserve firebase uids HOT 1
- TCP IP Disconnect Connecting to Server
- json2supabase generating duplicate records in postgres HOT 1
- How to migrate fireauth users whose provider is not email? HOT 1
- Inconsistent naming conventions between TS and JS files for Firestore custom processing hooks HOT 1
- Parsing error on auth migration HOT 7
- `Unexpected token export` when running storage upload HOT 1
- User failed to login on supabase HOT 5
- node firestore2json.js users.json fails HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from firebase-to-supabase.