Skip to content

Commit 0f03d7c

Browse files
committed
add nightly ORM test
1 parent 1eded64 commit 0f03d7c

12 files changed

Lines changed: 250 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: 'Doltgres ORM integration tests'
2+
description: 'Smoke tests for ORM integrations'
3+
runs:
4+
using: 'docker'
5+
image: '../../../testing/DoltgresORMDockerfile'
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Test Doltgres ORM integrations
2+
3+
on:
4+
workflow_dispatch:
5+
repository_dispatch:
6+
types: [ test-doltgres-orm-integrations ]
7+
8+
jobs:
9+
orm_integrations_job:
10+
runs-on: ubuntu-22.04
11+
timeout-minutes: 20
12+
name: Run tests
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
- name: Test Doltgres ORM integrations
17+
uses: ./.github/actions/orm-tests
18+
- name: Configure AWS Credentials
19+
if: ${{ failure() }}
20+
uses: aws-actions/configure-aws-credentials@v4
21+
with:
22+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
23+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
24+
aws-region: us-west-2
25+
- name: Send Email
26+
if: ${{ failure() }}
27+
uses: ./.github/actions/ses-email-action
28+
with:
29+
template: 'OrmIntegrationFailureTemplate'
30+
region: us-west-2
31+
version: ${{ github.ref }}
32+
toAddresses: '["jennifer@dolthub.com", "tim@dolthub.com"]'
33+
workflowURL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}

.github/workflows/nightly-performance-benchmarks-email-report.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ jobs:
2020
token: ${{ secrets.REPO_ACCESS_TOKEN }}
2121
event-type: sql-correctness
2222
client-payload: '{"version": "${{ github.sha }}", "mode": "nightly", "actor": "${{ github.actor }}", "template_script": "./.github/scripts/sql-correctness/get-doltgres-correctness-job-json.sh"}'
23+
- uses: peter-evans/repository-dispatch@v3
24+
with:
25+
token: ${{ secrets.REPO_ACCESS_TOKEN }}
26+
event-type: test-doltgres-orm-integrations

testing/DoltgresORMDockerfile

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
FROM --platform=${BUILDPLATFORM} ubuntu:22.04
2+
3+
# install ORM tools and dependencies
4+
ENV DEBIAN_FRONTEND=noninteractive
5+
RUN apt update -y && \
6+
apt install -y \
7+
curl \
8+
gnupg \
9+
software-properties-common && \
10+
curl -sL https://deb.nodesource.com/setup_22.x | bash - && \
11+
add-apt-repository ppa:deadsnakes/ppa -y && \
12+
sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' && \
13+
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg
14+
RUN apt update -y && \
15+
apt install -y \
16+
nodejs \
17+
python3.9 \
18+
python3-pip \
19+
git \
20+
bats \
21+
postgresql-server-dev-15 && \
22+
update-ca-certificates -f
23+
24+
# install go
25+
WORKDIR /root
26+
ENV GO_VERSION=1.25.0
27+
ENV GOPATH=/go
28+
ENV PATH=$PATH:$GOPATH/bin
29+
ENV PATH=$PATH:$GOPATH/bin:/usr/local/go/bin
30+
RUN curl -O "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz" && \
31+
sha256sum "go${GO_VERSION}.linux-amd64.tar.gz" && \
32+
tar -xvf "go${GO_VERSION}.linux-amd64.tar.gz" -C /usr/local && \
33+
chown -R root:root /usr/local/go && \
34+
mkdir -p $HOME/go/{bin,src} && \
35+
go version
36+
37+
# install doltgres from source
38+
WORKDIR /root/building
39+
COPY go.mod doltgresql/
40+
41+
# download dependencies first to persist Go dependencies download cache for doltgres despite other edits
42+
WORKDIR doltgresql
43+
RUN go mod download
44+
45+
# exclude clients directory to persist build-cache for doltgres when only editing ORM code
46+
COPY --exclude=testing/doltgres-orm-tests/ . .
47+
48+
# Build the parser
49+
WORKDIR /root/building/doltgresql/postgres/parser
50+
RUN bash ./build.sh
51+
52+
# Build the doltgres binary, which we will need for bats, and put it on PATH
53+
WORKDIR /root/building/doltgresql/cmd/doltgres
54+
RUN go build -o /usr/local/bin/doltgres .
55+
56+
COPY ./testing/doltgres-orm-tests /doltgres-orm-tests
57+
COPY ./testing/doltgres-orm-tests/doltgres-orm-tests-entrypoint.sh /doltgres-orm-tests/entrypoint.sh
58+
59+
WORKDIR /doltgres-orm-tests
60+
ENTRYPOINT ["/doltgres-orm-tests/entrypoint.sh"]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## PostgreSQL ORM Tests
2+
We created smoke tests for Doltgres's PostgreSQL ORM library integrations,
3+
and we run these tests through GitHub Actions on pull requests.
4+
5+
These tests can be run locally using Docker. From the doltgresql directory of the repo, run:
6+
7+
```bash
8+
$ docker build -t doltgres-orm-tests -f testing/DoltgresORMDockerfile .
9+
$ docker run doltgres-orm-tests:latest
10+
```
11+
12+
The `docker build` step will take a few minutes to complete
13+
as it needs to install all the dependencies in the image.
14+
15+
Running the built container will produce output like:
16+
```bash
17+
$ docker run orm-tests:latest
18+
Running Doltgres orm-tests:
19+
1..1
20+
ok 1 drizzle smoke test
21+
```
22+
docker run doltgres-orm-tests:latest
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
echo "Running Doltgres orm-tests:"
4+
bats /doltgres-orm-tests/doltgres-orm-tests.bats
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bats
2+
load $BATS_TEST_DIRNAME/helpers.bash
3+
4+
setup() {
5+
setup_doltgres_repo
6+
}
7+
8+
teardown() {
9+
teardown_doltgres_repo
10+
11+
# Check if postgresql is still running. If so stop it
12+
active=$(service postgresql status)
13+
if echo "$active" | grep "online"; then
14+
service postgresql stop
15+
fi
16+
}
17+
18+
@test "Drizzle smoke test" {
19+
# the schema should be empty
20+
# the dolt system tables are filtered out
21+
cd $BATS_TEST_DIRNAME/drizzle
22+
npm i drizzle-orm pg dotenv
23+
npm i -D drizzle-kit tsx @types/pg
24+
npx drizzle-kit push
25+
26+
# we can check if 'components table was created'
27+
query_server -c "SELECT * FROM components" -t
28+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import 'dotenv/config';
2+
import { defineConfig } from 'drizzle-kit';
3+
export default defineConfig({
4+
out: './drizzle',
5+
schema: './src/db/schema.ts',
6+
dialect: 'postgresql',
7+
dbCredentials: {
8+
url: 'postgres://postgres:password@localhost:5432/postgres',
9+
},
10+
tablesFilter: ["!dolt_*"], // IMPORTANT to filter out dolt system tables
11+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { jsonb, pgTable, text } from 'drizzle-orm/pg-core';
2+
3+
export const components = pgTable(
4+
'components',
5+
{
6+
id: text('id').notNull(),
7+
name: text('name'),
8+
description: text('description'),
9+
render: jsonb('render'),
10+
}
11+
);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import 'dotenv/config';
2+
import { Pool } from 'pg';
3+
import { drizzle } from 'drizzle-orm/node-postgres';
4+
import { components } from "./db/schema";
5+
6+
const params = {
7+
id: 'test',
8+
render: null,
9+
name: 'Test',
10+
description: null,
11+
};
12+
13+
const connectionString = 'postgres://postgres:password@localhost:5432/postgres';
14+
15+
const pool = new Pool({ connectionString });
16+
17+
const db = drizzle(pool);
18+
19+
await db
20+
.insert(components)
21+
.values(params)

0 commit comments

Comments
 (0)