mirror of
https://github.com/frappe/books.git
synced 2024-12-24 11:55:46 +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 = {
|
||||
client: 'sqlite3',
|
||||
connection: {
|
||||
filename: this.dbPath
|
||||
filename: this.dbPath,
|
||||
},
|
||||
pool: {
|
||||
afterCreate(conn, done) {
|
||||
conn.run('PRAGMA foreign_keys=ON');
|
||||
done();
|
||||
}
|
||||
},
|
||||
},
|
||||
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) {
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user