-
-
Notifications
You must be signed in to change notification settings - Fork 787
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2149 from drizzle-team/beta
Beta
- Loading branch information
Showing
36 changed files
with
3,167 additions
and
2,414 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
- 🎉 Added custom schema support to enums in Postgres (fixes #669 via #2048): | ||
|
||
```ts | ||
import { pgSchema } from 'drizzle-orm/pg-core'; | ||
|
||
const mySchema = pgSchema('mySchema'); | ||
const colors = mySchema.enum('colors', ['red', 'green', 'blue']); | ||
``` | ||
|
||
- 🎉 Changed D1 `migrate()` function to use batch API (#2137) | ||
- 🐛 Split `where` clause in Postgres `.onConflictDoUpdate` method into `setWhere` and `targetWhere` clauses, to support both `where` cases in `on conflict ...` clause (fixes #1628, #1302 via #2056) | ||
- 🐛 Fixed query generation for `where` clause in Postgres `.onConflictDoNothing` method, as it was placed in a wrong spot (fixes #1628 via #2056) | ||
- 🐛 Fixed multiple issues with AWS Data API driver (fixes #1931, #1932, #1934, #1936 via #2119) | ||
- 🐛 Fix inserting and updating array values in AWS Data API (fixes #1912 via #1911) | ||
|
||
Thanks @hugo082 and @livingforjesus! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,53 @@ | ||
import type { MigrationConfig } from '~/migrator.ts'; | ||
import { readMigrationFiles } from '~/migrator.ts'; | ||
import { sql } from '~/sql/sql.ts'; | ||
import type { DrizzleD1Database } from './driver.ts'; | ||
|
||
export async function migrate<TSchema extends Record<string, unknown>>( | ||
db: DrizzleD1Database<TSchema>, | ||
config: string | MigrationConfig, | ||
) { | ||
const migrations = readMigrationFiles(config); | ||
await db.dialect.migrate(migrations, db.session, config); | ||
const migrationsTable = config === undefined | ||
? '__drizzle_migrations' | ||
: typeof config === 'string' | ||
? '__drizzle_migrations' | ||
: config.migrationsTable ?? '__drizzle_migrations'; | ||
|
||
const migrationTableCreate = sql` | ||
CREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} ( | ||
id SERIAL PRIMARY KEY, | ||
hash text NOT NULL, | ||
created_at numeric | ||
) | ||
`; | ||
await db.session.run(migrationTableCreate); | ||
|
||
const dbMigrations = await db.values<[number, string, string]>( | ||
sql`SELECT id, hash, created_at FROM ${sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`, | ||
); | ||
|
||
const lastDbMigration = dbMigrations[0] ?? undefined; | ||
|
||
const statementToBatch = []; | ||
|
||
for (const migration of migrations) { | ||
if (!lastDbMigration || Number(lastDbMigration[2])! < migration.folderMillis) { | ||
for (const stmt of migration.sql) { | ||
statementToBatch.push(db.run(sql.raw(stmt))); | ||
} | ||
|
||
statementToBatch.push( | ||
db.run( | ||
sql`INSERT INTO ${sql.identifier(migrationsTable)} ("hash", "created_at") VALUES(${ | ||
sql.raw(`'${migration.hash}'`) | ||
}, ${sql.raw(`${migration.folderMillis}`)})`, | ||
), | ||
); | ||
} | ||
} | ||
|
||
if (statementToBatch.length > 0) { | ||
await db.session.batch(statementToBatch); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.