Skip to content
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

Add option to disable generation of FKs #2548

Closed
ramiel opened this issue Dec 17, 2021 · 14 comments
Closed

Add option to disable generation of FKs #2548

ramiel opened this issue Dec 17, 2021 · 14 comments
Labels
enhancement New feature or request
Milestone

Comments

@ramiel
Copy link

ramiel commented Dec 17, 2021

To support myISAM. Not to be confused with migrations.disableForeignKeys config option.

@ramiel ramiel changed the title Foeeign key option ignored Foreign key option ignored Dec 17, 2021
@B4nan
Copy link
Member

B4nan commented Dec 17, 2021

disableForeignKeys is not an option to "disable generation of FKs". it never was. it only controls if the schema commands will be wrapped in set foreign_key_checks = 0 and set foreign_key_checks = 1. Also note that the default value is true.

@B4nan B4nan closed this as completed Dec 17, 2021
@ramiel
Copy link
Author

ramiel commented Dec 17, 2021

Oh, in version 4 it disabled foreign key constraint creation. What changed here? How do I disable foreign key creation? Not all the mysql DB use the InnoDB engine

@B4nan
Copy link
Member

B4nan commented Dec 17, 2021

It did not change, it never worked that way.

@B4nan
Copy link
Member

B4nan commented Dec 17, 2021

What changed is that FKs are not properly diffed, in general schema diffing now works as it should.

@ramiel
Copy link
Author

ramiel commented Dec 17, 2021

Ok. Question remains. Is there a way to avoid creating foreign key constraints?

@ramiel
Copy link
Author

ramiel commented Dec 17, 2021

Basically any MySQL db based on https://vitess.io/ won't work with version 5. An example is https://planetscale.com/

@B4nan
Copy link
Member

B4nan commented Dec 17, 2021

No it is not, there never was one. Feel free to send a PR, but it would have to be a top level configuration (that will be then feeded to the SchemaGenerator methods as part of their options), nothing about migrations, migrations just work with SchemaGenerator.

Note that you still can use v5, you just need to remove the FK queries from your migrations manually if you don't want them there. That is the whole point of migrations, as you have absolute control over that.

@ramiel
Copy link
Author

ramiel commented Dec 17, 2021

Thanks. I have no time to provide a PR and the codebase is too big, sorry.

Note that you still can use v5, you just need to remove the FK queries from your migrations manually if you don't want them there

Can you explain more about this?

@B4nan
Copy link
Member

B4nan commented Dec 17, 2021

@B4nan
Copy link
Member

B4nan commented Dec 17, 2021

Let's keep this open, I don't want to sound like I don't see this as something valid. But to me it feels like an edge case, it's been a decade since I came accross someone actually using myisam :D Might be just my bubble :D

@B4nan B4nan reopened this Dec 17, 2021
@B4nan B4nan changed the title Foreign key option ignored Add option to disable generation of FKs Dec 17, 2021
@B4nan B4nan added the enhancement New feature or request label Dec 17, 2021
@ramiel
Copy link
Author

ramiel commented Dec 17, 2021

So, let me explain better what I mean. In my code, during startup in dev mode, I have something like this

const generator = orm.getSchemaGenerator();
    
await generator.updateSchema({
  wrap: false,
  safe: true,
  dropDb: false,
  dropTables: false,
});

this way I'm sure DB is up to date with my models. Maybe it's the wrong way, I don't know. If this fails, I print the needed update on console and I run manually. Having an option to disable foreign key contraints would avoid me to run anything manually.

On the other side, I'm not talking about myIsam. I don't know anybody using it. I'm talking about a new generation of cloud-centric mysql based DBs that have very large scalability performances. In a previous message I mentioned one of those (planetscale) and an engine very popular and used (vitess).

I'll try to find the time to work on this and propose a PR, but I'm afrai I really have not much time. What would take me hours or days to be done/tested and so on, it's for sure much less for whoever has already familiarity with the codebase. I'm not saying I want you to do it, I'm just asking if by any chance this can be done.

Thanks for the support

@B4nan
Copy link
Member

B4nan commented Dec 17, 2021

this way I'm sure DB is up to date with my models. Maybe it's the wrong way, I don't know. If this fails, I print the needed update on console and I run manually. Having an option to disable foreign key contraints would avoid me to run anything manually.

It's not wrong, but I would be quite cautious with this in a production environment (but yeah, with safe: true it should be ok'ish). I wouldn't trust the schema diffing in v4 that much, v5 should be a different story, it's much smarter :]

Note that you are using schema generator, so nothing you specify in migrations config has any effect on that, its a different layer, hence my confusion as you were talking about configuring how migrations work.

And indeed, to me it will probably take an hour or two, to you it can take much more. But you are the one who needs it (actually the first one to ask for it). If you don't have time to collaborate, you can always sponsor the development, especially if this is something you need for a project that will bring you some revenue.

I'm not saying I want you to do it, I'm just asking if by any chance this can be done.

The sad fact is that pretty much all the issues wait for me to work on them. Only a small portion of people will try to contribute, many of them will send an incomplete (often failing) PR and never even reply to my feedback. I usually ask for that in issues like this one, where it really is easy task to achieve. Often I don't even want others to contribute, if it's something touching internals as it can easily have breaking effect to other parts of the codebase.

@ramiel
Copy link
Author

ramiel commented Dec 17, 2021

As a maintainer of open source projects, I understand you well. I already contributed with a small PR when I could in the past.
Something about the sponsorship. This issue specifically comes form a need of mine in a personal project but we (hypersay.events) use your library in our product (recently released). Your project was in our list of open source projects to give a sign of gratitude, then we were quite busy and distracted and being a small team things get confusing sometimes :)

So yes, definitely expect something from us soon, but I don't want to use sponsorship as a way to push our needs in any way. Good job so far!

It's not wrong, but I would be quite cautious with this in a production environment

No, I'm not using this in production

@varHarrie
Copy link

Is there an option to avoid creating foreign key constraints? Just like createForeignKeyConstraints from typeorm.

@B4nan B4nan added this to the 5.0 milestone Jan 15, 2022
@B4nan B4nan closed this as completed in fcdb236 Jan 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants