Skip to content

Commit 231cf3a

Browse files
authored
remove prisma and implement knex (#15)
1 parent b00a1e0 commit 231cf3a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1148
-594
lines changed

.github/workflows/bench.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: BENCH
22

33
on:
44
push:
5+
branches: [master]
56
paths-ignore:
67
- 'docs/**'
78
- '*.md'
@@ -45,13 +46,16 @@ jobs:
4546
run: npm ci --prefer-offline --no-audit
4647

4748
- name: Create db schema
48-
run: DATABASE_URL="postgresql://postgres:changeme@localhost:5440/graphql-registry?schema=public" npx prisma db push --preview-feature
49+
run: |
50+
docker exec -t postgres createdb -U postgres graphql-registry
51+
DATABASE_URL="postgresql://postgres:changeme@localhost:5440/graphql-registry?schema=public" npm run migrate
4952
5053
- name: Build app image
5154
run: docker-compose up -d app
5255

5356
- name: Bench
5457
run: |
58+
sleep 5
5559
docker-compose run k6 run /benchmark/composed-schema.js
5660
5761
- name: Clean services

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: CI
22

33
on:
44
push:
5+
branches: [master]
56
paths-ignore:
67
- 'docs/**'
78
- '*.md'

Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ WORKDIR /usr/src/app
44

55
COPY package*.json ./
66

7-
COPY prisma ./
8-
97
RUN npm ci
108

119
COPY . .

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ This activates authorization in the `/schema/push` endpoint. Only the client wit
184184
```
185185
docker-compose up postgres
186186
# Create db schema
187-
npx prisma db push --preview-feature
187+
npm run migrate
188188
npm run dev
189189
npm run test
190190
```

knexfile.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
client: 'pg',
3+
connection: process.env.DATABASE_URL,
4+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
*
3+
* @param {import("knex").Knex} knex
4+
* @returns
5+
*/
6+
exports.up = (knex) => {
7+
return knex.schema
8+
.createTable('graph', (table) => {
9+
table.increments('id').primary().notNullable()
10+
11+
table.string('name').unique().notNullable()
12+
table.boolean('isActive').notNullable().defaultTo(true)
13+
table.timestamp('createdAt', { useTz: true }).notNullable().defaultTo(knex.fn.now())
14+
table.timestamp('updatedAt', { useTz: true }).notNullable().defaultTo(knex.fn.now())
15+
})
16+
.createTable('service', (table) => {
17+
table.increments('id').primary()
18+
19+
table.string('name')
20+
table.boolean('isActive').notNullable().defaultTo(true)
21+
table.timestamp('createdAt', { useTz: true }).notNullable().defaultTo(knex.fn.now())
22+
table.timestamp('updatedAt', { useTz: true }).notNullable().defaultTo(knex.fn.now())
23+
24+
table.integer('graphId').unsigned().references('id').inTable('graph').index()
25+
})
26+
.createTable('schema', (table) => {
27+
table.increments('id').primary()
28+
29+
table.string('typeDefs')
30+
table.boolean('isActive').notNullable().defaultTo(true)
31+
table.timestamp('createdAt', { useTz: true }).notNullable().defaultTo(knex.fn.now())
32+
table.timestamp('updatedAt', { useTz: true }).notNullable().defaultTo(knex.fn.now())
33+
table.integer('graphId').unsigned().references('id').inTable('graph').index()
34+
35+
table.integer('serviceId').unsigned().references('id').inTable('service').index()
36+
})
37+
.createTable('schema_tag', (table) => {
38+
table.increments('id').primary()
39+
40+
table.string('version')
41+
table.boolean('isActive').notNullable().defaultTo(true)
42+
table.timestamp('createdAt', { useTz: true }).notNullable().defaultTo(knex.fn.now())
43+
table.timestamp('updatedAt', { useTz: true }).notNullable().defaultTo(knex.fn.now())
44+
45+
table.integer('schemaId').unsigned().references('id').inTable('schema').index()
46+
})
47+
}
48+
49+
/**
50+
*
51+
* @param {import("knex").Knex} knex
52+
* @returns
53+
*/
54+
exports.down = (knex) => {
55+
return knex.schema
56+
.raw('DROP TABLE graph CASCADE')
57+
.raw('DROP TABLE schema CASCADE')
58+
.raw('DROP TABLE schema_tag CASCADE')
59+
.raw('DROP TABLE service CASCADE')
60+
}

0 commit comments

Comments
 (0)