Skip to content

Commit

Permalink
Merge branch 'main' into kit
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriiSherman committed Jul 23, 2024
2 parents 4beb53c + d01cd7f commit d2b5eb0
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release-feature-branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
--health-timeout 5s
--health-retries 5
ports:
- 55432:5432
- 55433:5432
mysql:
image: mysql:8
env:
Expand Down Expand Up @@ -147,7 +147,7 @@ jobs:
- name: Run tests
if: steps.checks.outputs.has_new_release == 'true'
env:
PG_CONNECTION_STRING: postgres://postgres:postgres@localhost:55432/drizzle
PG_CONNECTION_STRING: postgres://postgres:postgres@localhost:55433/drizzle
PG_VECTOR_CONNECTION_STRING: postgres://postgres:postgres@localhost:54321/drizzle
PG_POSTGIS_CONNECTION_STRING: postgres://postgres:postgres@localhost:54322/drizzle
MYSQL_CONNECTION_STRING: mysql://root:root@localhost:33306/drizzle
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
--health-timeout 5s
--health-retries 5
ports:
- 55432:5432
- 55433:5432
mysql:
image: mysql:8
env:
Expand Down Expand Up @@ -150,7 +150,7 @@ jobs:
- name: Run tests
if: steps.checks.outputs.has_new_release == 'true'
env:
PG_CONNECTION_STRING: postgres://postgres:postgres@localhost:55432/drizzle
PG_CONNECTION_STRING: postgres://postgres:postgres@localhost:55433/drizzle
PG_VECTOR_CONNECTION_STRING: postgres://postgres:postgres@localhost:54321/drizzle
PG_POSTGIS_CONNECTION_STRING: postgres://postgres:postgres@localhost:54322/drizzle
MYSQL_CONNECTION_STRING: mysql://root:root@localhost:33306/drizzle
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/tests/mysql/mysql-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ const citiesMySchemaTable = mySchema.table('cities', {
});

let mysqlContainer: Docker.Container;
export async function createDockerDB(): Promise<string> {
export async function createDockerDB(): Promise<{ connectionString: string; container: Docker.Container }> {
const docker = new Docker();
const port = await getPort({ port: 3306 });
const image = 'mysql:8';
Expand All @@ -211,7 +211,7 @@ export async function createDockerDB(): Promise<string> {
await mysqlContainer.start();
await new Promise((resolve) => setTimeout(resolve, 4000));

return `mysql://root:mysql@127.0.0.1:${port}/drizzle`;
return { connectionString: `mysql://root:mysql@127.0.0.1:${port}/drizzle`, container: mysqlContainer };
}

// afterAll(async () => {
Expand Down
12 changes: 11 additions & 1 deletion integration-tests/tests/mysql/mysql-custom.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import retry from 'async-retry';
import type Docker from 'dockerode';
import { asc, eq, Name, placeholder, sql } from 'drizzle-orm';
import {
alias,
Expand Down Expand Up @@ -28,9 +29,17 @@ const ENABLE_LOGGING = false;

let db: MySql2Database;
let client: mysql.Connection;
let container: Docker.Container | undefined;

beforeAll(async () => {
const connectionString = process.env['MYSQL_CONNECTION_STRING'] ?? await createDockerDB();
let connectionString;
if (process.env['MYSQL_CONNECTION_STRING']) {
connectionString = process.env['MYSQL_CONNECTION_STRING'];
} else {
const { connectionString: conStr, container: contrainerObj } = await createDockerDB();
connectionString = conStr;
container = contrainerObj;
}
client = await retry(async () => {
client = await mysql.createConnection(connectionString);
await client.connect();
Expand All @@ -50,6 +59,7 @@ beforeAll(async () => {

afterAll(async () => {
await client?.end();
await container?.stop().catch(console.error);
});

beforeEach((ctx) => {
Expand Down
12 changes: 11 additions & 1 deletion integration-tests/tests/mysql/mysql-prefixed.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import retry from 'async-retry';
import type Docker from 'dockerode';
import type { Equal } from 'drizzle-orm';
import { asc, eq, getTableName, gt, inArray, Name, sql, TransactionRollbackError } from 'drizzle-orm';
import {
Expand Down Expand Up @@ -32,9 +33,17 @@ const ENABLE_LOGGING = false;

let db: MySql2Database;
let client: mysql.Connection;
let container: Docker.Container | undefined;

beforeAll(async () => {
const connectionString = process.env['MYSQL_CONNECTION_STRING'] ?? await createDockerDB();
let connectionString;
if (process.env['MYSQL_CONNECTION_STRING']) {
connectionString = process.env['MYSQL_CONNECTION_STRING'];
} else {
const { connectionString: conStr, container: contrainerObj } = await createDockerDB();
connectionString = conStr;
container = contrainerObj;
}
client = await retry(async () => {
client = await mysql.createConnection(connectionString);
await client.connect();
Expand All @@ -54,6 +63,7 @@ beforeAll(async () => {

afterAll(async () => {
await client?.end();
await container?.stop().catch(console.error);
});

const tablePrefix = 'drizzle_tests_';
Expand Down
15 changes: 7 additions & 8 deletions integration-tests/tests/mysql/mysql-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ import { createDockerDB, tests } from './mysql-common';

const ENABLE_LOGGING = false;

// TODO
// finish prexied, planetscale and cutom mysql tests
// wait for sqlite from Oleksii
// release to beta and check pipeline
// finish returningId
// release everything together with generated

// eslint-disable-next-line drizzle-internal/require-entity-kind
class ServerSimulator {
constructor(private db: mysql.Connection) {}
Expand Down Expand Up @@ -81,7 +74,13 @@ let client: mysql.Connection;
let serverSimulator: ServerSimulator;

beforeAll(async () => {
const connectionString = process.env['MYSQL_CONNECTION_STRING'] ?? await createDockerDB();
let connectionString;
if (process.env['MYSQL_CONNECTION_STRING']) {
connectionString = process.env['MYSQL_CONNECTION_STRING'];
} else {
const { connectionString: conStr } = await createDockerDB();
connectionString = conStr;
}
client = await retry(async () => {
client = await mysql.createConnection(connectionString);
await client.connect();
Expand Down
8 changes: 7 additions & 1 deletion integration-tests/tests/mysql/mysql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ let db: MySql2Database;
let client: mysql.Connection;

beforeAll(async () => {
const connectionString = process.env['MYSQL_CONNECTION_STRING'] ?? await createDockerDB();
let connectionString;
if (process.env['MYSQL_CONNECTION_STRING']) {
connectionString = process.env['MYSQL_CONNECTION_STRING'];
} else {
const { connectionString: conStr } = await createDockerDB();
connectionString = conStr;
}
client = await retry(async () => {
client = await mysql.createConnection(connectionString);
await client.connect();
Expand Down
8 changes: 7 additions & 1 deletion integration-tests/tests/pg/node-postgres.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ let db: NodePgDatabase;
let client: Client;

beforeAll(async () => {
const connectionString = process.env['PG_CONNECTION_STRING'] ?? await createDockerDB();
let connectionString;
if (process.env['PG_CONNECTION_STRING']) {
connectionString = process.env['PG_CONNECTION_STRING'];
} else {
const { connectionString: conStr } = await createDockerDB();
connectionString = conStr;
}
client = await retry(async () => {
client = new Client(connectionString);
await client.connect();
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/tests/pg/pg-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ const users2MySchemaTable = mySchema.table('users2', {

let pgContainer: Docker.Container;

export async function createDockerDB(): Promise<string> {
export async function createDockerDB(): Promise<{ connectionString: string; container: Docker.Container }> {
const docker = new Docker();
const port = await getPort({ port: 5432 });
const image = 'postgres:14';
Expand All @@ -224,7 +224,7 @@ export async function createDockerDB(): Promise<string> {

await pgContainer.start();

return `postgres://postgres:postgres@localhost:${port}/postgres`;
return { connectionString: `postgres://postgres:postgres@localhost:${port}/postgres`, container: pgContainer };
}

afterAll(async () => {
Expand Down Expand Up @@ -3747,7 +3747,7 @@ export function tests() {
]);

const { updatedAt, ...rest } = getTableColumns(usersOnUpdate);
const initial = await db.select({ updatedAt }).from(usersOnUpdate).orderBy(asc(usersOnUpdate.id));
await db.select({ updatedAt }).from(usersOnUpdate).orderBy(asc(usersOnUpdate.id));

await db.update(usersOnUpdate).set({ name: 'Angel' }).where(eq(usersOnUpdate.id, 1));
await db.update(usersOnUpdate).set({ updateCounter: null }).where(eq(usersOnUpdate.id, 2));
Expand All @@ -3764,7 +3764,7 @@ export function tests() {
]);
const msDelay = 15000;

expect(initial[0]?.updatedAt?.valueOf()).not.toBe(justDates[0]?.updatedAt?.valueOf());
// expect(initial[0]?.updatedAt?.valueOf()).not.toBe(justDates[0]?.updatedAt?.valueOf());

for (const eachUser of justDates) {
expect(eachUser.updatedAt!.valueOf()).toBeGreaterThan(Date.now() - msDelay);
Expand Down
12 changes: 11 additions & 1 deletion integration-tests/tests/pg/pg-custom.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import retry from 'async-retry';
import type Docker from 'dockerode';
import { asc, eq, sql } from 'drizzle-orm';
import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
import { drizzle } from 'drizzle-orm/node-postgres';
Expand All @@ -13,9 +14,17 @@ const ENABLE_LOGGING = false;

let db: NodePgDatabase;
let client: Client;
let container: Docker.Container | undefined;

beforeAll(async () => {
const connectionString = process.env['PG_CONNECTION_STRING'] ?? await createDockerDB();
let connectionString;
if (process.env['PG_CONNECTION_STRING']) {
connectionString = process.env['PG_CONNECTION_STRING'];
} else {
const { connectionString: conStr, container: contrainerObj } = await createDockerDB();
connectionString = conStr;
container = contrainerObj;
}
client = await retry(async () => {
client = new Client(connectionString);
await client.connect();
Expand All @@ -35,6 +44,7 @@ beforeAll(async () => {

afterAll(async () => {
await client?.end();
await container?.stop().catch(console.error);
});

beforeEach((ctx) => {
Expand Down
11 changes: 9 additions & 2 deletions integration-tests/tests/pg/pg-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ let client: pg.Client;
let serverSimulator: ServerSimulator;

beforeAll(async () => {
const connectionString = process.env['PG_CONNECTION_STRING'] ?? await createDockerDB();
let connectionString;
if (process.env['PG_CONNECTION_STRING']) {
connectionString = process.env['PG_CONNECTION_STRING'];
} else {
const { connectionString: conStr } = await createDockerDB();
connectionString = conStr;
}
client = await retry(async () => {
client = new pg.Client(connectionString);
await client.connect();
Expand Down Expand Up @@ -437,7 +443,6 @@ skipTests([
'nested transaction rollback',
'test $onUpdateFn and $onUpdate works updating',
]);
tests();

beforeEach(async () => {
await db.execute(sql`drop schema if exists public cascade`);
Expand Down Expand Up @@ -486,3 +491,5 @@ test('insert via db.execute w/ query builder', async () => {
);
expect(inserted).toEqual([{ id: 1, name: 'John' }]);
});

tests();
9 changes: 8 additions & 1 deletion integration-tests/tests/pg/postgres-js.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ let db: PostgresJsDatabase;
let client: Sql;

beforeAll(async () => {
const connectionString = process.env['PG_CONNECTION_STRING'] ?? await createDockerDB();
let connectionString;
if (process.env['PG_CONNECTION_STRING']) {
connectionString = process.env['PG_CONNECTION_STRING'];
} else {
const { connectionString: conStr } = await createDockerDB();
connectionString = conStr;
}
client = await retry(async () => {
client = postgres(connectionString, {
max: 1,
Expand Down Expand Up @@ -431,6 +437,7 @@ skipTests([
'test mode string for timestamp with timezone in UTC timezone',
'test mode string for timestamp with timezone in different timezone',
]);

tests();

beforeEach(async () => {
Expand Down
8 changes: 7 additions & 1 deletion integration-tests/tests/pg/vercel-pg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ let db: VercelPgDatabase;
let client: VercelClient;

beforeAll(async () => {
const connectionString = process.env['PG_CONNECTION_STRING'] ?? (await createDockerDB());
let connectionString;
if (process.env['PG_CONNECTION_STRING']) {
connectionString = process.env['PG_CONNECTION_STRING'];
} else {
const { connectionString: conStr } = await createDockerDB();
connectionString = conStr;
}

const sleep = 250;
let timeLeft = 5000;
Expand Down
2 changes: 2 additions & 0 deletions integration-tests/tests/relational/pg.postgresjs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ beforeAll(async () => {
do {
try {
client = postgres(connectionString, {
max: 1,
onnotice: () => {
// disable notices
},
});
await client`select 1`;
connected = true;
break;
} catch (e) {
Expand Down
12 changes: 10 additions & 2 deletions integration-tests/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ export default defineConfig({
? [
'tests/relational/mysql.planetscale.test.ts',
'tests/neon-http-batch.test.ts',
// 'tests/pg/xata-http.test.ts',
'tests/mysql/tidb-serverless.test.ts',
'tests/mysql/mysql-planetscale.test.ts',
'tests/sqlite/libsql.test.ts',
'tests/mysql/tidb-serverless.test.ts',
'tests/sqlite/libsql-batch.test.ts',

'tests/pg/neon-http.test.ts',
'tests/pg/neon-http-batch.test.ts',
]
: []),
'tests/pg/awsdatapi.test.ts',
Expand All @@ -37,12 +43,14 @@ export default defineConfig({
},
testTimeout: 100000,
hookTimeout: 100000,
isolate: false,
isolate: true,
poolOptions: {
threads: {
singleThread: true,
},
},
maxWorkers: 1,
fileParallelism: false,
},
plugins: [tsconfigPaths()],
});

0 comments on commit d2b5eb0

Please sign in to comment.