mirror of
https://github.com/frappe/books.git
synced 2024-12-25 04:06:04 +00:00
feat: sqlite schema update hack
This commit is contained in:
parent
187446e3aa
commit
8da2332c74
@ -8,16 +8,16 @@ class SqliteDatabase extends Database {
|
|||||||
this.connectionParams = {
|
this.connectionParams = {
|
||||||
client: 'sqlite3',
|
client: 'sqlite3',
|
||||||
connection: {
|
connection: {
|
||||||
filename: this.dbPath
|
filename: this.dbPath,
|
||||||
},
|
},
|
||||||
pool: {
|
pool: {
|
||||||
afterCreate(conn, done) {
|
afterCreate(conn, done) {
|
||||||
conn.run('PRAGMA foreign_keys=ON');
|
conn.run('PRAGMA foreign_keys=ON');
|
||||||
done();
|
done();
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
useNullAsDefault: true,
|
useNullAsDefault: true,
|
||||||
asyncStackTraces: process.env.NODE_ENV === 'development'
|
asyncStackTraces: process.env.NODE_ENV === 'development',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,12 +48,12 @@ class SqliteDatabase extends Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getTableColumns(doctype) {
|
async getTableColumns(doctype) {
|
||||||
return (await this.sql(`PRAGMA table_info(${doctype})`)).map(d => d.name);
|
return (await this.sql(`PRAGMA table_info(${doctype})`)).map((d) => d.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getForeignKeys(doctype) {
|
async getForeignKeys(doctype) {
|
||||||
return (await this.sql(`PRAGMA foreign_key_list(${doctype})`)).map(
|
return (await this.sql(`PRAGMA foreign_key_list(${doctype})`)).map(
|
||||||
d => d.from
|
(d) => d.from
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,6 +103,17 @@ class SqliteDatabase extends Database {
|
|||||||
}
|
}
|
||||||
return errorType;
|
return errorType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async prestigeTheTable(tableName, tableRows) {
|
||||||
|
// Alter table hacx for sqlite in case of schema change.
|
||||||
|
const tempName = `__${tableName}`;
|
||||||
|
await this.knex.raw('PRAGMA foreign_keys=OFF');
|
||||||
|
await this.createTable(tableName, tempName);
|
||||||
|
await this.knex.batchInsert(tempName, tableRows);
|
||||||
|
await this.knex.schema.dropTable(tableName);
|
||||||
|
await this.knex.schema.renameTable(tempName, tableName);
|
||||||
|
await this.knex.raw('PRAGMA foreign_keys=ON');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = SqliteDatabase;
|
module.exports = SqliteDatabase;
|
||||||
|
Loading…
Reference in New Issue
Block a user