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

Schema generator- Skip Tables and Skip Columns #5346

Open
cloud303-mbrughelli opened this issue Mar 15, 2024 · 4 comments
Open

Schema generator- Skip Tables and Skip Columns #5346

cloud303-mbrughelli opened this issue Mar 15, 2024 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@cloud303-mbrughelli
Copy link

Is your feature request related to a problem? Please describe.
Piggy-backing off this issue that was implemented: issue ,
I'd like the ability to skip certain tables or columns during schema generation. I am using supabase which has an auth schema by default that has a users table that I want the entity for but many other tables that I don't need. I do have "auth" set in the ignoreSchema array option on the schemaGenerator in my config. But obviously that makes the generator think that auth.users needs to be created. If I remove "auth" from the array, it tries to remove everything from auth that isn't the users table.

Describe the solution you'd like
A skipTables and skipColumns option in the schemaGenerator.

Describe alternatives you've considered
I've moved on by defining a normal PK for my public.profile table that is not linked to the foreign users key in the auth schema. This is not ideal as it's important to me to maintain the FK constraints.

@cloud303-mbrughelli cloud303-mbrughelli added the enhancement New feature or request label Mar 15, 2024
@B4nan
Copy link
Member

B4nan commented Mar 16, 2024

So you have auth.user table, you have an entity for it, and you want to ignore the rest of the schema? And you want to have only some columns mapped in your entity? Limiting what we infer from existing schema when diffing?

@cloud303-mbrughelli
Copy link
Author

So you have auth.user table, you have an entity for it, and you want to ignore the rest of the schema? And you want to have only some columns mapped in your entity? Limiting what we infer from existing schema when diffing?

That is correct. I realize it's not critical and there are plenty of workarounds. Just an idea I had based on the functionality existing in the other direction (Entity Generator). I appreciate the response! Mikro- Orm is the GOAT, really loving it. Thank you for your work.

@stefansundin
Copy link
Contributor

I would love for a way to create indexes that aren't even considered by the schema migrator. I am creating some manual indexes that I don't think I can create using the decorators. Here is an example (I'm using postgresql):

create index "manual_blog_post_search_index" on "blog_post" ("user_id", lower("title") collate "C", "created_at", "category_id");

In this case I need lower("title") so that I can do a case-insensitive prefix search on the title, and I need to use collate "C" because postgresql requires this collation for prefix search using the ^@ operator.

For context, I use this in my query:

[raw('lower("title") ^@ ?', [titlePrefix])]: [],

So this is an example of an index that I don't think mikro-orm can create using the decorators, which is fine because I am perfectly happy creating them manually. But the annoying part is that the migration generator wants to remove them. 😭

I think one simple solution would be to ignore indexes whose name doesn't start with the table name. All mikro-orm indexes starts with the table name (e.g. blog_post_), so if I prefix my manual indexes with something else (manual_ in this example), then it would be great if mikro-orm used that to understand that it did not create this index and thus it shouldn't try to remove it.

I hope that makes sense. :)

@B4nan
Copy link
Member

B4nan commented Apr 12, 2024

You can create any index via index expressions, see the title property in this example https://mikro-orm.io/docs/defining-entities#indexes.

@B4nan B4nan added help wanted Extra attention is needed good first issue Good for newcomers labels Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants