-
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
1 parent
78dee90
commit 33a0f48
Showing
3 changed files
with
62 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`migrationBuilder > should expose MigrationBuilder to allow using as sql builder 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,44 @@ | ||
import { describe, expect, it, vi } from 'vitest'; | ||
import { MigrationBuilder } from '../src'; | ||
|
||
describe('migrationBuilder', () => { | ||
it('should expose MigrationBuilder to allow using as sql builder', () => { | ||
const pgm = new MigrationBuilder( | ||
{ | ||
query: vi.fn(), | ||
select: vi.fn(), | ||
}, | ||
undefined, | ||
true, | ||
console | ||
); | ||
|
||
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(); | ||
}); | ||
}); |