-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Defined Schema at server start and simple migrations #7063
Comments
We are currently using node migrate for this, to upgrade Schemas and keep them in sync across environments. We store the state of the migration in a master-key only Parse.Config entry. app.ts
Parse Statestore
example of migration file
|
thanks @timanrebel for the suggestion, i think it could be nice to support a method that allow developers to execute some data manipulation (with node migrate or other tools) before deleting fields after schemas update. I take in count that we should have system similar to We can have this type of trigger:
Or a more flexible approach With this kind of trigger developers will have all tools to run some complex databases operations before pushing any changes. |
@Moumouls I played with your Gist snippet and the schema generations works pretty well, congrats for the nice job!
Unfortunately, it seems that enabling single schema cache does not fixes the issue :(
Without the RedisAdapter everything works fine, but I have no idea how to enable it after that on the fly. I'm deploying on Heroku using MongoDB Any ideas? |
@L3K0V what is your database? |
I was thinking if this might cause a problem. I'm using throng with 1 worker, one dyno for now and believe this is not the issue.
Indeed I have some default values or required, but what do you propose about them, I mean - Can I have them? I'm not changing them within different deployments. Restarting the dyno sometimes fixes the generation. |
On the PR i need to add a retry system for better handling in case of parallel deployment (when all Parse server starts at the same time).
You can use it , but changing/removing defaultValue/required will trigger a field reset (my script delete the field then create the field with new options. Sadly the field concerned by the change will be deleted on all objects.) @L3K0V can you try to set |
I was able to deploy without issues. Looking at the @timanrebel snippet above I put a error check not to kill the process. Not sure if this cause some side effects on migrations, what do you thunk @Moumouls?
|
Okay so we need to check how Parse server currently use cache on Schema queries ( In your use case it seems that Redis is just out of date. Then if you remove the |
It seems also that schema cache TTL, is not applied correctly in Schema Cache instance. setAllClasses(schema) {
if (!this.ttl) {
return Promise.resolve(null);
}
return this.cache.put(this.prefix + MAIN_SCHEMA, schema);
// expected code: return this.cache.put(this.prefix + MAIN_SCHEMA, schema, this.ttl);
} We need to fix this in my PR also |
Hey @Moumouls. Want to share some new findings:
It's very strange. Let me know if I can help somehow. |
Thanks @L3K0V for your investigation. So now I'm sure that the "random" fails come from concurrency of your node cluster, because multiple parse server will try to update schemas at the same time. I think throng do not support rolling update policy. But here no problem I know what we have to do, to reduce errors from concurrency. The script just need a retry system ( attempt to migrate schema, if fail, wait 2 sec then retry, at the 5th fail exit), then each parse server will try to ensure the schema structure and most of the time the 2nd try will be sufficient for all parse servers instances to be okay since we need at least one parse server to perform the schema updates. I will work on this, and try to add some tests :) |
@L3K0V if you want to give a try to the new defined schema feature, you can install temporary on your repo my forked package branch: Then on parse server options you can use the ex: const server = ParseServer.start({
schemas: [{ className: '_User', fields: { aNewField: { type: 'String'}} }, { className: 'Test' }],
beforeSchemasMigration: async () => {
// Some code if you want to execute something before migration ops
},
}); The schema structure is the same as my script that you have used before (JSON Schema). |
I was actually looking for such a functionality where you could specify the schemas on startup. This seems impossible as far as I know, so I'll be happy to try it out soon as well. Btw it would be handy if you could pass an array of Parse.Schema (https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html). |
Hi @jonas-db , i will be happy to get your feedback from my forked package version for this feature
(this version is stable) Usage: const server = ParseServer.start({
schemas: [{ className: '_User', fields: { aNewField: { type: 'String'}} }, { className: 'Test' }],
beforeSchemasMigration: async () => {
// Some code if you want to execute something before migration ops
},
}); |
Closing via #7418 |
Is your feature request related to a problem? Please describe.
Schema less behavior of Parse Server is hard to maintain accros multi envs and creates some complications in using the new GraphQL API correctly.
Describe the solution you'd like
Allow the pass a JSON REST version of a Parse Schema to the Parse Server options. Then parse server will push/migrate schema to the DB.
Describe alternatives you've considered
Need a custom script into serverStartComplete
Additional context
Currently the feature could be achieve with https://gist.github.com/Moumouls/e4f0c6470398efc7a6a74567982185fa
This script is currently used in prod during 1 year, no issue detected.
Community discussion here: https://community.parseplatform.org/t/possibility-to-set-class-level-permissions-via-file/1061/22
The text was updated successfully, but these errors were encountered: