@fewer/adapter-postgres
Version:
A Fewer database adapter to connect to Postgres
58 lines • 2.33 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fewer_1 = require("fewer");
const __1 = require("../");
const migrate_1 = __importDefault(require("../migrate"));
const database = fewer_1.createDatabase({
adapter: new __1.Adapter({}),
});
const VERSION = 1;
describe('migration', () => {
describe('createTable Down', () => {
it('generates drop table sql', () => {
const migration = fewer_1.createMigration(VERSION, database, {
change: (m, t) => m.createTable('users', { primaryKey: 'id' }, {
id: t.bigserial(),
firstName: t.string(),
lastName: t.string(),
email: t.string({ nonNull: true }),
}),
});
migration.prepare('up');
const sql = migrate_1.default(migration);
expect(sql).toMatchSnapshot();
});
});
describe('createTable Up', () => {
it('generates create table sql', () => {
const migration = fewer_1.createMigration(VERSION, database, {
change: (m, t) => m.createTable('users', { primaryKey: 'id' }, {
id: t.bigserial(),
firstName: t.string(),
lastName: t.string(),
email: t.string({ nonNull: true }),
}),
});
migration.prepare('up');
const sql = migrate_1.default(migration);
expect(sql).toMatchSnapshot();
});
it('supports unique constraint', () => {
const migration = fewer_1.createMigration(VERSION, database, {
change: (m, t) => m.createTable('users', { primaryKey: 'id' }, {
id: t.bigserial(),
firstName: t.string(),
lastName: t.string(),
email: t.string({ unique: true, nonNull: true }),
}),
});
migration.prepare('up');
const sql = migrate_1.default(migration);
expect(sql).toMatchSnapshot();
});
});
});
//# sourceMappingURL=changeMigrations.test.js.map