-
Notifications
You must be signed in to change notification settings - Fork 1.9k
unable to set migration strategy per model #4542
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
Comments
@chestercharles Thanks for posting, we'll take a look as soon as possible. For help with questions about Sails, click here. If you’re interested in hiring @sailsbot and her minions in Austin, click here. |
@chestercharles The Sails v1.0 breaking changes log states, "The experimental |
@johnabrams7 , I don't think the " For example, in my case I have a The Model Settings documentation state they "can be specified on a per-model basis by setting top-level properties in a model definition". I would assume this includes the |
After digging into the sails-hook-orm, it appears that auto-migrations are performed using whatever migration strategy is set in
I would expect that the orm hook would also inspect the |
Hi @chestercharles, Also here are the official docs for migration for easy access: |
Hi @raqem, thanks for looking into the issue. My confusion is not about what the different migration strategies do, but rather why Sails no longer supports The documentation says:
However, in Sails v1 this is not the case - the In Sails v0.12.9 I was able to have a different I could certainly be misunderstanding something, but this appears to be a breaking change? |
Hi @raqem. Does my previous question make sense? Have you and your team had a chance to take a look at this yet? |
I have the same issue that @chestercharles it's commenting. I have the inverse situation, my db is so big that my migration it's on safe and i want to alter or drop certain models but keep safe migration for the rest of the models. |
I've been working around this by making the
However, this is a sloppy hack and would not work in @krewx 's situation. Does Sails plan to support setting migration strategies per model? |
Hi @chestercharles, |
@raqem thanks! But dont hurt anyone on my account! 😳 |
Hey @chestercharles @krewx, My understanding is that this was done to avoid having a situation where associated models have different migration strategies and by one slip up become a massive tangle and database death-heap. |
@raqem I did see that note in the docs, but I thought it was just a suggestion. Here is my case why you should consider supporting it:In most real life situations, an application is going to need to interact with more data sources than just the core CRUD models, eg. like 3rd party APIs. Sails/Waterline is awesome because it provides an adapter specification (and generator) so that I can integrate these different datastores into my applications and interact with them using the sails model APIs. However, if I need to use a datastore that is read-only (say, to integrate data from an external system), without being able to specify migration strategies per model (or at least per datastore) I can no longer use the migration feature of sails. Also, I can no longer use the sails-disk adapter for quick-rev development since I can't really manually migrate models with sails-disk. And for any relational databases I want to use, I have to manually create all the tables. I feel like dropping support for this feature undermines the benefits of the adapter-based approach of waterline. It is going to be too much of a burden to use Sails to develop applications that need data from external systems via waterline adapters. My two cents - thanks for your consideration and happy Thanksgiving :) |
The option to set the migration strategy on a per-model basis was incredibly useful. Maybe using another migration tool is safer but I'm not going to do it. I keep coming back to Sails because the ORM is badass but this change makes the ORM significantly less useful. Please bring it back |
Hi @alwaysAn0n, |
Hey ya'll @chestercharles, @krewx, @alwaysAn0n |
Thanks for the quick response Sails team!
That's a totally valid concern. I would do it like this. When trying to auto-migrate a particular model, check if it actually does have associations. If yes, refuse to migrate ( and log a warning ) unless all associated models share the same per-model migration strategy as the model in question. If the model in question doesn't have associations, migrate using the specified per-model migration strategy. As for submitting a PR, I might be able to do that. Would this only require a change in |
@alwaysAn0n all automigrations logic is driven by sails-hook-orm, but it does use some utilities in waterline-utils. So this is something that'd mostly live in waterline-utils, I think, but it'll definitely involve |
I'm experiencing the same thing. Seems counter intuitive to force migration policy at the entire app level, as it removes our ability to integrate legacy databases with stuff we're newly developing. I'm looking at: and https://github.com/sailshq/waterline-utils/blob/master/lib/auto-migrations/index.js Am I correct in observing that it determines the automigration policy at the app level via Looking at this in particular:
It looks like Is there a reason we can't inspect the migrate type on the WLModel? We don't even really need to worry about migrations happening on our new application database, all for that, but being able to specify This is the only thing that is stopping me from wanting to move forward with Sails, so I'm very motivated to help make it happen. Going to |
@mikermcneil made a couple PRs to address this. I imagine you'll want some things changed, but would like your feedback and to know what I need to change or do get it in. Thanks! This update allows specifying |
Hey Mike, I also wanted to thank you and the team for making Sails, and look forward to using it to make life easier! |
@atomiccc thanks! I like (a lot) the idea of it being per-datastore rather than per-model (makes way more sense) -- for consistency, I think that'll mean updating the docs to change it from a model setting to a standard datastore config key. The only problem is that this way is potentially a breaking change, depending on how we do it. And realistically, the right way to do this is with a breaking change, since that way we're not adding a bunch of deprecation warnings and stuff we have to unwind later. I'd like to hear some other thoughts too, just to get a sense of whether this change would obviously mess anyone up in some way we're not anticipating. |
I’m not sure why this would be a breaking change. It seems like there should be a default (app-wide) migration strategy if one isn’t specified. That’s the current behavior and nothing to deprecate. This feature should only build on that; use the strategy added to the adapter, if specified. Ideally, though, setting the strategy in the adapter is still too wide. I don’t want to discount the concerns and complications previously mentioned, but the migration strategy should be a per-model setting. I have models that are simple ORM interfaces to database views. For instance, I’ve been granted access to an HR employee view of a database I don’t administer. I don’t have permission to drop those views, nor would I want to. They are read-only data, which should also not be replicated in another database to honor data governance policies. In other databases, which I do have write access, I don’t want to accidentally drop tables that are managed by other applications. For instance, let’s say I’m building a notification interface to notify user lists of varying system events. This notifier queries varying database looking for conditions that trigger a notification and build a subsequent report with more details of the data. I may want to log that in an area of that database (maybe in a log db schema), without being able to drop those main tables. That requires different migration strategies w/in the same database — unless the advice is to have two adapters/connections to the same database (read stream vs write stream). I know Mike may not be looking for parroting the original idea, but wanted to reinforce that there are countless cases where I have needed to perform migrations on a per-model basis and it makes sense to be able to set migrations at the three layers:
Since only the app is currently available, I’d be fine with using the database as the next stepping stone for that capability. I don’t want to get rid of the app ability as there are lots of projects that are also self contained and it makes sense to include it for backwards compatibility (and prevent a breaking change). |
Hi @Kontributer Thanks alot for your thoughtful feedback.
But we have counted you as a vote for 'in favor of changing how strict migration settings are' |
this is not useful as long as there is no feature to automatically create migration such as django. |
Hey, @vikas-0! We're continuing to monitor community opinion on this topic, and we appreciate your feedback! |
Hey guys - just wanted to add my support for a model-level setting for migration strategy. I'm working with user data in an external database whereas all my other data is in its own database. I can't drop the external tables so this is giving me issues at the minute. If anybody has any workarounds I could use please let me know! |
The workaround I used was temporarily commenting out all models I didn't want migrated then lifting the app. If the ORM doesn't know the models exist in the datastore, it won't fuck with them. |
Yeah this is what I ended up doing also. It's a bit of an annoying warkaround though. |
I just wanted to add my support for a model-level and/or adapter-level setting for migration strategy. I'm looking at a REST adapter, which does not want migrations performed ever. |
Hi, I'm in a similar situation. In my case y develop a json based adapter to use with preloaded data that will not change. I have one or two models working with it and the rest of the them with mongo. Right now my only option is to change my drop & define to prevent the erase, but it would be great to override the migration strategy model based. Thank all the people working hard to make sails a great framework!!! And if I can in the near feature I will be releasing the db adapter (made on top of low db). |
Hey, all. I'm working on Sails Content which will definitely benefit from having a per-model or per-datastore migration. I am going to take a stab to see if I can land a PR for this. |
Sails version: 1.0.2
Node version: 8.9.4
NPM version: 6.1.0
DB adapter name: sails-disk
DB adapter version: version that ships with sails 1.0.2
Operating system: Windows 8.1 Enterprise
Howdy,
I've started to use Sails v1 for new projects after using v0.12 for many previous projects. In v0.12, I set a migration strategy I wanted to use for my models in
config/models.js
.For a given model, I could set a different migration strategy in that model file (eg.
api/models/Kitten.js
) that would override what was inconfig/models.js
.When the server lifted, it would honor this model-specific migration strategy, and leave my kittens data intact.
Is this no longer the default behavior in v1.x? I do not see this on the list of breaking changes when upgrading to v1.
Steps to reproduce (or see this repo):
sails generate new testapp1
sails generate model kitten
sails generate model puppy
migrate: 'drop'
inconfig/models.js
node app.js
http://localhost:1337/kitten/create
a couple times to generate some kittens.migrate: 'safe
toapi/models/Kitten.js
node app.js
http://localhost:1337/kitten
... we've lost all the kittens.The text was updated successfully, but these errors were encountered: