-
Notifications
You must be signed in to change notification settings - Fork 279
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
In a migration, how to refer to the type created by db.schema.createType #1269
Comments
It looks like |
Try wrapping the type in double quotes:
|
I get the same error with double quotes |
You've also got an extra |
Sorry - I wrote but didn't run the minimal repro above, hence the syntax error. I've now tried running the actual minimal repro as the only migration on a fresh DB:
(this is the only migration in src/db/migrations and the DB is brand new)
This happens both with and without double quotes. If I remove the createTable statement, the type is correctly created in the target schema:
|
Here's a self-contained repro: https://github.com/jroitgrund/kysely-repo clone and run
BTW, with the following diff
the migration completes, which is what's leading me to believe that kysely isn't prepending the schema name to the custom type in the createTable statement. |
Kysely doesn't parse raw SQL and therefore has no idea what you wrote inside your raw sql snippet. For that reason, it can't prefix it with the schema. We already have the We should add something like Alternatively we could allow ANY string in the second argument of |
Thanks for taking a look! Do you have a suggested workaround in the meantime? I tried setting the schema as a field on the DB instance before migrating so I can manually prepend it to the type name, but since the DB object passed to the migrator is actually a transaction, this doesn't work.
My hunch is that schemableId would work better than implicitly treating anything 'unrecognized' as schemable, because some of the types which currently require raw SQL aren't "schemable" (e.g. types added by extensions, array types). For example,
|
Yeah there's a way. I can write a https://kyse.link for you in a bit. |
Actually I couldn't figure out a way to do that currently 😞 I think the only way is to somehow pass in the schema using an environment variable or a global variable and glue it to the type manually 😬 |
Unfortunately, my use case is one-schema-per-test and running tests concurrently. I'll keep an eye on the issue, thanks for the quick replies :) |
When using a custom schema
the following migraiton fails:
I get
(presumably because the type needs to be prefixed with the schema).
How can I fix this? I don't know how to access the schema name from the migration to manually prefix it.
Note that none of the sql helpers (.ref, .table, etc) seem to fix this.
The text was updated successfully, but these errors were encountered: