Skip to content

Commit

Permalink
Merge branch 'beta' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriiSherman authored Nov 27, 2023
2 parents 8ce46e5 + aad4fe0 commit b5eb2c2
Show file tree
Hide file tree
Showing 20 changed files with 578 additions and 55 deletions.
8 changes: 3 additions & 5 deletions drizzle-orm/src/mysql-proxy/migrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export async function migrate<TSchema extends Record<string, unknown>>(
id: sql.raw('id'),
hash: sql.raw('hash'),
created_at: sql.raw('created_at'),
}).from(sql.raw(migrationsTable)).orderBy(
sql.raw('created_at desc'),
}).from(sql.identifier(migrationsTable).getSQL()).orderBy(
sql.raw('created_at desc')
).limit(1);

const lastDbMigration = dbMigrations[0];
Expand All @@ -41,9 +41,7 @@ export async function migrate<TSchema extends Record<string, unknown>>(
) {
queriesToRun.push(
...migration.sql,
`insert into ${
sql.identifier(migrationsTable)
} (\`hash\`, \`created_at\`) values(${migration.hash}, ${migration.folderMillis})`,
`insert into ${sql.identifier(migrationsTable).value} (\`hash\`, \`created_at\`) values('${migration.hash}', '${migration.folderMillis}')`,
);
}
}
Expand Down
12 changes: 8 additions & 4 deletions drizzle-orm/src/pg-proxy/migrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ export async function migrate<TSchema extends Record<string, unknown>>(
await db.execute(sql`CREATE SCHEMA IF NOT EXISTS "drizzle"`);
await db.execute(migrationTableCreate);

const dbMigrations = await db.execute(
sql`SELECT id, hash, created_at FROM "drizzle"."__drizzle_migrations" ORDER BY created_at DESC LIMIT 1`,
) as unknown as [number, string, string][];
const dbMigrations = await db.execute<{
id: number;
hash: string;
created_at: string;
}>(
sql`SELECT id, hash, created_at FROM "drizzle"."__drizzle_migrations" ORDER BY created_at DESC LIMIT 1`
);

const lastDbMigration = dbMigrations[0] ?? undefined;

Expand All @@ -34,7 +38,7 @@ export async function migrate<TSchema extends Record<string, unknown>>(
for (const migration of migrations) {
if (
!lastDbMigration
|| Number(lastDbMigration[2])! < migration.folderMillis
|| Number(lastDbMigration.created_at)! < migration.folderMillis
) {
queriesToRun.push(
...migration.sql,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE `userstest` (
`id` serial PRIMARY KEY,
`name` text NOT NULL,
`verified` boolean NOT NULL DEFAULT false,
`jsonb` json,
`created_at` timestamp NOT NULL DEFAULT now()
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"version": "5",
"dialect": "mysql",
"id": "8e8c8378-0496-40f6-88e3-98aab8282b1f",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"userstest": {
"name": "userstest",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": false,
"autoincrement": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"verified": {
"name": "verified",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false,
"autoincrement": false
},
"jsonb": {
"name": "jsonb",
"type": "json",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()",
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {}
}
},
"schemas": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
}
}
13 changes: 13 additions & 0 deletions integration-tests/drizzle2/mysql-proxy/first/meta/_journal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "5",
"dialect": "mysql",
"entries": [
{
"idx": 0,
"version": "5",
"when": 1680270921944,
"tag": "0000_nostalgic_carnage",
"breakpoints": true
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE `userstest` (
`id` serial PRIMARY KEY,
`name` text NOT NULL,
`verified` boolean NOT NULL DEFAULT false,
`jsonb` json,
`created_at` timestamp NOT NULL DEFAULT now()
);
5 changes: 5 additions & 0 deletions integration-tests/drizzle2/mysql-proxy/second/0001_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE `users12` (
`id` serial AUTO_INCREMENT PRIMARY KEY NOT NULL,
`name` text NOT NULL,
`email` text NOT NULL
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"version": "5",
"dialect": "mysql",
"id": "8e8c8378-0496-40f6-88e3-98aab8282b1f",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"userstest": {
"name": "userstest",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": false,
"autoincrement": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"verified": {
"name": "verified",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false,
"autoincrement": false
},
"jsonb": {
"name": "jsonb",
"type": "json",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()",
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {}
}
},
"schemas": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"version": "5",
"dialect": "mysql",
"id": "47362df0-c353-4bd1-8107-fcc36f0e61bd",
"prevId": "8e8c8378-0496-40f6-88e3-98aab8282b1f",
"tables": {
"userstest": {
"name": "userstest",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": false,
"autoincrement": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"verified": {
"name": "verified",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false,
"autoincrement": false
},
"jsonb": {
"name": "jsonb",
"type": "json",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()",
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {}
},
"users12": {
"name": "users12",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {
"my_unique_index": {
"name": "my_unique_index",
"columns": ["name"],
"isUnique": true,
"using": "btree"
}
},
"foreignKeys": {},
"compositePrimaryKeys": {}
}
},
"schemas": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
}
}
20 changes: 20 additions & 0 deletions integration-tests/drizzle2/mysql-proxy/second/meta/_journal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "5",
"dialect": "mysql",
"entries": [
{
"idx": 0,
"version": "5",
"when": 1680270921944,
"tag": "0000_nostalgic_carnage",
"breakpoints": true
},
{
"idx": 1,
"version": "5",
"when": 1680270921945,
"tag": "0001_test",
"breakpoints": true
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE "users" (
id serial PRIMARY KEY,
name text NOT NULL,
verified boolean NOT NULL DEFAULT false,
jsonb jsonb,
created_at timestamptz NOT NULL DEFAULT now()
);
56 changes: 56 additions & 0 deletions integration-tests/drizzle2/pg-proxy/first/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"version": "5",
"dialect": "pg",
"id": "cb1644bb-c5da-465a-8d70-f63d81e34514",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"users": {
"name": "users",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"verified": {
"name": "verified",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false
},
"jsonb": {
"name": "jsonb",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamptz",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {}
}
},
"enums": {},
"schemas": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
}
}
Loading

0 comments on commit b5eb2c2

Please sign in to comment.