How do I migrate a codebase from ndb to SQLalchemy?
Tempted to write a parser/emitter, taking in the 40+ ndb.Model of my codebase and generate sqlalchemy.schema.Table or Base inheriting classes. But that doesn't:
- solve the data migration problem;
- doesn't enable a middle-road, where I can access data before migrating;
- requires manual work in migrating all the query syntax over
Happy to do the work, but asking here in case there's a better way (e.g., I saw this 10-year old question Can SQLAlchemy be used with Google Cloud SQL? ; or maybe some way of dumping the schema directly from ndb to SQL then from SQL directly to SQLalchemy).
To migrate you need to write a migration script that will copy data from the old datastore to the new one. You can use the ndb library to read from the old datastore and the sqlalchemy library to write to the new one. You can't do it automatically. You can't do it partially. You can't do it in a way that will allow you to access data before migrating. You can't do it without manual work. You can't do it without writing a migration script.
Superficial example of a migration script: