nice
This commit is contained in:
parent
80c6db1abd
commit
f370a2fe68
2 changed files with 3 additions and 8 deletions
3
index.js
3
index.js
|
|
@ -27,11 +27,14 @@ function applyMigrations() {
|
||||||
);
|
);
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
|
||||||
const migrationsDir = path.join(__dirname, '/migrations');
|
const migrationsDir = path.join(__dirname, '/migrations');
|
||||||
const migrationFiles = fs.readdirSync(migrationsDir).filter(file => file.endsWith('.sql'));
|
const migrationFiles = fs.readdirSync(migrationsDir).filter(file => file.endsWith('.sql'));
|
||||||
|
|
||||||
migrationFiles.forEach(file => {
|
migrationFiles.forEach(file => {
|
||||||
const isApplied = db.prepare('SELECT filename FROM migrations WHERE filename = ?').get(file);
|
const isApplied = db.prepare('SELECT filename FROM migrations WHERE filename = ?').get(file);
|
||||||
|
|
||||||
|
console.log(!isApplied, file)
|
||||||
if (!isApplied) {
|
if (!isApplied) {
|
||||||
const sql = fs.readFileSync(path.join(migrationsDir, file), 'utf-8');
|
const sql = fs.readFileSync(path.join(migrationsDir, file), 'utf-8');
|
||||||
db.exec(sql);
|
db.exec(sql);
|
||||||
|
|
|
||||||
|
|
@ -35,13 +35,6 @@ CREATE TABLE routes (
|
||||||
FOREIGN KEY(structure_id) REFERENCES structures(structure_id),
|
FOREIGN KEY(structure_id) REFERENCES structures(structure_id),
|
||||||
FOREIGN KEY(user_id) REFERENCES users(user_id)
|
FOREIGN KEY(user_id) REFERENCES users(user_id)
|
||||||
);
|
);
|
||||||
CREATE TABLE migrations (
|
|
||||||
migration_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
db_id INTEGER,
|
|
||||||
sql_content TEXT NOT NULL,
|
|
||||||
name TEXT NOT NULL,
|
|
||||||
FOREIGN KEY(db_id) REFERENCES dbs(db_id)
|
|
||||||
);
|
|
||||||
CREATE TABLE structure_dbs (
|
CREATE TABLE structure_dbs (
|
||||||
db_id INTEGER,
|
db_id INTEGER,
|
||||||
structure_id INTEGER,
|
structure_id INTEGER,
|
||||||
|
|
@ -56,4 +49,3 @@ CREATE TABLE structure_templates (
|
||||||
FOREIGN KEY(template_id) REFERENCES templates(template_id),
|
FOREIGN KEY(template_id) REFERENCES templates(template_id),
|
||||||
FOREIGN KEY(structure_id) REFERENCES structures(structure_id)
|
FOREIGN KEY(structure_id) REFERENCES structures(structure_id)
|
||||||
);
|
);
|
||||||
a
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue