-
-
Notifications
You must be signed in to change notification settings - Fork 560
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
Unique property causes issue when generating a migration on a schema scoped table #1215
Comments
A follow up on this, I was tinkering around with the migration generated some more and noticed that if I edit the constraint from |
I don't think we need to prefix constraint names, they will exist inside the schema only. The fix should be just about not passing the schema name inside. Will need to check, I believe we are not explicitly setting the name anywhere and its knex doing it, but it is definitely possible to set it explicitly. |
Wait a minute, I got confused, thought its a FK constraint. You can set the unique constraint name manually already: @Property({
unique: 'column_name_uniq',
})
columnName: string; or @Property()
@Unique({ name: 'column_name_uniq' })
columnName: string; |
Looks like explicitly providing the unique constraint by name works! This is the resulting migration: @Entity({
tableName: "schemaName.tableName",
})
export class TableName {
// ... other columns
@Property({
unique: "column_name_unique",
})
columnName: string;
} alter table "schemaName"."tableName"
add constraint "column_name_unique" unique ("column_name"); |
@B4nan this does not solve the error scenario for primary key constraints. It keeps adding the schema. I'm on version 4.3.5-dev.28 Example:
|
@B4nan updates on this? |
currently in the middle of full rewrite for schema diffing, targetting v5 as it will probably require some breaking changes. so you will need to wait a bit more, if you will see the same with v5, open new issue with full reproduction. edit: but open for PR if its not a big change |
Describe the bug
When generating a migration for a table that is a part of a specific schema (a la
@Entity({ tableName: "schemaName.tableName" })
), the migrator will generate an invalid SQL statement.This is where I decorate a column:
I also tried it like this and it produced the same result:
This is what is generated:
However when I remove the
"schemaName".
prefix from the constraint like this, the migration successfully ran as expected.Stack trace
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The migrator was expected to produce a valid SQL statement.
** Additional Context **
Using with Nest.js, however I don't think that is impacting this behavior.
Versions
The text was updated successfully, but these errors were encountered: