48 lines
4.0 KiB
JavaScript
48 lines
4.0 KiB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
import Migration from "../db/Migration";
|
|
import { query } from "../db/MysqlConnectionManager";
|
|
/**
|
|
* Must be the first migration
|
|
*/
|
|
export default class CreateMigrationsTable extends Migration {
|
|
shouldRun(currentVersion) {
|
|
const _super = Object.create(null, {
|
|
shouldRun: { get: () => super.shouldRun }
|
|
});
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
try {
|
|
yield query('SELECT 1 FROM migrations LIMIT 1');
|
|
}
|
|
catch (e) {
|
|
if (e.code !== 'ER_NO_SUCH_TABLE') {
|
|
return false;
|
|
}
|
|
}
|
|
return yield _super.shouldRun.call(this, currentVersion);
|
|
});
|
|
}
|
|
install() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
yield query('CREATE TABLE migrations(' +
|
|
'id INT NOT NULL,' +
|
|
'name VARCHAR(64) NOT NULL,' +
|
|
'migration_date DATE,' +
|
|
'PRIMARY KEY (id)' +
|
|
')');
|
|
});
|
|
}
|
|
rollback() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
yield query('DROP TABLE migrations');
|
|
});
|
|
}
|
|
}
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ3JlYXRlTWlncmF0aW9uc1RhYmxlLmpzIiwic291cmNlUm9vdCI6Ii4vIiwic291cmNlcyI6WyJtaWdyYXRpb25zL0NyZWF0ZU1p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