Skip to content

Commit

Permalink
feat: add mysql dialect (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
avallete authored Apr 29, 2024
1 parent 5686d78 commit 79d464a
Show file tree
Hide file tree
Showing 79 changed files with 6,799 additions and 8,584 deletions.
3 changes: 3 additions & 0 deletions .github/docker/Dockerfile.mysql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM mysql:8

CMD ["mysqld", "--wait_timeout=28800", "--interactive_timeout=28800"]
5 changes: 5 additions & 0 deletions .github/docker/Dockerfile.postgres
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM postgres:16

# Use a shell script to modify config and start PostgreSQL

CMD ["postgres", "-c", "max_connections=300"]
26 changes: 23 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ defaults:
env:
SNAPLET_DISABLE_TELEMETRY: '1'
PG_TEST_DATABASE_SERVER: postgresql://postgres:postgres@localhost:5432/postgres
MYSQL_TEST_DATABASE_SERVER: mysql://root@localhost:3306/mysql
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
CI: '1'

jobs:
test-type-check:
Expand Down Expand Up @@ -73,20 +75,38 @@ jobs:
test-unit-integration:
if: github.event.pull_request.draft == false
name: Unit and integration tests
runs-on: buildjet-16vcpu-ubuntu-2204
runs-on: buildjet-32vcpu-ubuntu-2204
services:
postgres:
image: postgres:16
# Custom image built with higher max_connections for vitests parralelization
# See docker/Dockerfile.postgres to see how it was built
image: avallete/postgres-custom-ci
credentials:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
mysql:
# Custom image built with higher timeout for vitest parralelization
# See docker/Dockerfile.mysql to see how it was built
image: avallete/mysql-custom-ci
credentials:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
ports:
- 3306:3306
env:
MYSQL_ALLOW_EMPTY_PASSWORD: true
MYSQL_DATABASE: mysql
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
49 changes: 45 additions & 4 deletions packages/seed/e2e/api/e2e.api.connect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ for (const [dialect, adapter] of adapterEntries) {
// eslint-disable-next-line vitest/expect-expect, vitest/valid-title
_test.concurrent(computeName(name), fn);
};

test("connect callback needs only ids", async () => {
const schema: SchemaRecord = {
default: `
Expand All @@ -38,6 +37,18 @@ for (const [dialect, adapter] of adapterEntries) {
"userId" integer not null references "User"("id")
);
`,
mysql: `
CREATE TABLE \`User\` (
id INT AUTO_INCREMENT PRIMARY KEY,
fullName TEXT NOT NULL
);
CREATE TABLE \`Post\` (
id INT AUTO_INCREMENT PRIMARY KEY,
userId INT NOT NULL,
FOREIGN KEY (userId) REFERENCES \`User\` (id)
);
`,
};

const { db } = await setupProject({
Expand All @@ -56,7 +67,9 @@ for (const [dialect, adapter] of adapterEntries) {
`,
});

const posts = await db.query<{ fullName: string }>('select * from "Post"');
const posts = await db.query<{ fullName: string }>(
`select * from ${adapter.escapeIdentifier("Post")}`,
);

expect(posts).toEqual([
{
Expand Down Expand Up @@ -98,6 +111,18 @@ for (const [dialect, adapter] of adapterEntries) {
"userId" integer not null references "User"("id")
);
`,
mysql: `
CREATE TABLE \`User\` (
id INT AUTO_INCREMENT PRIMARY KEY,
fullName TEXT NOT NULL
);
CREATE TABLE \`Post\` (
id INT AUTO_INCREMENT PRIMARY KEY,
userId INT NOT NULL,
FOREIGN KEY (userId) REFERENCES \`User\` (id)
);
`,
};

const { db } = await setupProject({
Expand All @@ -116,7 +141,9 @@ for (const [dialect, adapter] of adapterEntries) {
`,
});

const posts = await db.query<{ fullName: string }>('select * from "Post"');
const posts = await db.query<{ fullName: string }>(
`select * from ${adapter.escapeIdentifier("Post")}`,
);

expect(posts).toEqual([
{
Expand Down Expand Up @@ -158,6 +185,18 @@ for (const [dialect, adapter] of adapterEntries) {
"userId" integer not null references "User"("id")
);
`,
mysql: `
CREATE TABLE \`User\` (
id INT AUTO_INCREMENT PRIMARY KEY,
fullName TEXT NOT NULL
);
CREATE TABLE \`Post\` (
id INT AUTO_INCREMENT PRIMARY KEY,
userId INT NOT NULL,
FOREIGN KEY (userId) REFERENCES \`User\` (id)
);
`,
};

const { db } = await setupProject({
Expand All @@ -180,7 +219,9 @@ for (const [dialect, adapter] of adapterEntries) {
`,
});

const posts = await db.query<{ fullName: string }>('select * from "Post"');
const posts = await db.query<{ fullName: string }>(
`select * from ${adapter.escapeIdentifier("Post")}`,
);

expect(posts).toEqual([
{
Expand Down
Loading

0 comments on commit 79d464a

Please sign in to comment.