-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose createMigrationBuilder to allow using this lib as sql bu…
…ilder
- Loading branch information
Showing
4 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`createMigrationBuilder > should generate the proper sql 1`] = ` | ||
"CREATE TABLE "users" ( | ||
"id" serial PRIMARY KEY, | ||
"name" varchar(1000) NOT NULL, | ||
"created_at" timestamp DEFAULT current_timestamp NOT NULL | ||
); | ||
CREATE TABLE "posts" ( | ||
"id" serial PRIMARY KEY, | ||
"user_id" integer NOT NULL REFERENCES "users" ON DELETE CASCADE, | ||
"body" text NOT NULL, | ||
"created_at" timestamp DEFAULT current_timestamp NOT NULL | ||
); | ||
CREATE INDEX "posts_user_id_index" ON "posts" ("user_id"); | ||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { createMigrationBuilder } from '../src'; | ||
|
||
describe('createMigrationBuilder', () => { | ||
it('should generate the proper sql', () => { | ||
const pgm = createMigrationBuilder(); | ||
pgm.createTable('users', { | ||
id: 'id', | ||
name: { type: 'varchar(1000)', notNull: true }, | ||
createdAt: { | ||
type: 'timestamp', | ||
notNull: true, | ||
default: pgm.func('current_timestamp'), | ||
}, | ||
}); | ||
pgm.createTable('posts', { | ||
id: 'id', | ||
userId: { | ||
type: 'integer', | ||
notNull: true, | ||
references: '"users"', | ||
onDelete: 'CASCADE', | ||
}, | ||
body: { type: 'text', notNull: true }, | ||
createdAt: { | ||
type: 'timestamp', | ||
notNull: true, | ||
default: pgm.func('current_timestamp'), | ||
}, | ||
}); | ||
pgm.createIndex('posts', 'userId'); | ||
expect(pgm.getSql()).toMatchSnapshot(); | ||
}); | ||
}); |