Bug fixes
- [BUG]: error: type "serial" does not exist
- [BUG]: jsonb default with boolean literals gets generated truen instead of true
- [BUG]: MSSQL view incorrect syntax
- Fixed
blobcolumns in MySQL to work properly with RQB mapper
Changes to SQLite drizzle-kit up command
Important!
If you were already using SQLite in any
beta.xversion and have used thedrizzle-kit upcommand, you will not receive the latestupchanges from this release. If you are unable to reset migrations and start from scratch, you will need to contact us for support with upgrading
What was changed?
Handling of UNIQUE constraints in SQLite
In the new version drizzle-kit handles UNIQUE constraints. This decision was made because when a unique constraint is created it cannot be removed, whereas an index can be dropped
Previous version of Drizzle-Kit always created .unique() as a uniqueIndex and stored it in the snapshot that way. Because of this during an up we lack of sufficient information and if a user used .unique() an upped will generate a diff on generate and push
Solution:
We are replacing all unique constraints with uniqueIndex
uniqueIndex requires a name and the name must follow this format:
<table>_<column1>*_*<column2>_..._unique
Foreign key name handling in the old(pre 1.0) drizzle-kit
The old drizzle-kit did not handle foreign key names when generated sql migrations. A foreign key name could be defined in the ts schema, but it was not passed through when generating sql
export const table = sqliteTable("table", {
column1: integer(),
column2: integer()},
(t) => [
foreignKey({
name: "name",
columns: [t.column1],
foreignColumns: [t.column2],
}),
]
);
// no name provided
FOREIGN KEY (`timest`) REFERENCES `b`(`timest1`) ON UPDATE no action ON DELETE no actionOn introspect new drizzle-kit parses ddl to find constraint name, if no name found - use default name
After running drizzle-kit up the first push command will result in a diff that recreates the table (no name from db, but there is name in ts schema). To avoid this foreign key names should be removed - in that case no diff will be generated.
drizzle-kit generate command will behave as expected, no changes needed.
Bug in the old drizzle-kit related to foreign keys
If you add a column to an existing table that has a foreign key and specify onDelete or onUpdate, column will be added with the foreign key, but without those parameters
export const table = sqliteTable("table", {
column1: integer()
});
export const table = sqliteTable("table", {
column1: integer(),
column2: integer().references((): AnySQLiteColumn => table.column1,
{
onDelete: "set null",
onUpdate: "set default"
})
});
ALTER TABLE `table` ADD `column2` integer REFERENCES table(column1);There is no way to fix this in the old snapshot. It led to table recreation during subsequent push operations (in the pre-v1.0 drizzle-kit version)
New drizzle-kit will recreate table after push command with the correct SQL. When using generate command, no diffs will appear, but the actual database state may differ