|
|
@ -1548,7 +1548,11 @@ class SqliteClient extends KnexClient { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const pkQuery = this.alterTablePK(args.columns, args.originalColumns, upQuery); |
|
|
|
const pkQuery = this.alterTablePK( |
|
|
|
|
|
|
|
args.columns, |
|
|
|
|
|
|
|
args.originalColumns, |
|
|
|
|
|
|
|
upQuery |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await this.sqlClient.raw('PRAGMA foreign_keys = OFF;'); |
|
|
|
await this.sqlClient.raw('PRAGMA foreign_keys = OFF;'); |
|
|
|
await this.sqlClient.raw('PRAGMA legacy_alter_table = ON;'); |
|
|
|
await this.sqlClient.raw('PRAGMA legacy_alter_table = ON;'); |
|
|
@ -1565,7 +1569,9 @@ class SqliteClient extends KnexClient { |
|
|
|
|
|
|
|
|
|
|
|
if (pkQuery) { |
|
|
|
if (pkQuery) { |
|
|
|
await trx.schema.alterTable(args.table, (table) => { |
|
|
|
await trx.schema.alterTable(args.table, (table) => { |
|
|
|
for (const pk of pkQuery.oldPks.filter((el) => !pkQuery.newPks.includes(el))) { |
|
|
|
for (const pk of pkQuery.oldPks.filter( |
|
|
|
|
|
|
|
(el) => !pkQuery.newPks.includes(el) |
|
|
|
|
|
|
|
)) { |
|
|
|
table.dropPrimary(pk); |
|
|
|
table.dropPrimary(pk); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1947,7 +1953,7 @@ class SqliteClient extends KnexClient { |
|
|
|
newPks, |
|
|
|
newPks, |
|
|
|
oldPks, |
|
|
|
oldPks, |
|
|
|
dropPks, |
|
|
|
dropPks, |
|
|
|
} |
|
|
|
}; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
@ -2004,33 +2010,49 @@ class SqliteClient extends KnexClient { |
|
|
|
shouldSanitize |
|
|
|
shouldSanitize |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
let addNewColumnQuery = '' |
|
|
|
let addNewColumnQuery = ''; |
|
|
|
addNewColumnQuery += this.genQuery(` ADD ?? ${n.dt}`, [n.cn], shouldSanitize); |
|
|
|
addNewColumnQuery += this.genQuery( |
|
|
|
|
|
|
|
` ADD ?? ${n.dt}`, |
|
|
|
|
|
|
|
[n.cn], |
|
|
|
|
|
|
|
shouldSanitize |
|
|
|
|
|
|
|
); |
|
|
|
addNewColumnQuery += n.dtxp && n.dt !== 'text' ? `(${n.dtxp})` : ''; |
|
|
|
addNewColumnQuery += n.dtxp && n.dt !== 'text' ? `(${n.dtxp})` : ''; |
|
|
|
addNewColumnQuery += n.cdf ? ` DEFAULT ${n.cdf}` : !n.rqd ? ' ' : ` DEFAULT ''`; |
|
|
|
addNewColumnQuery += n.cdf |
|
|
|
|
|
|
|
? ` DEFAULT ${n.cdf}` |
|
|
|
|
|
|
|
: !n.rqd |
|
|
|
|
|
|
|
? ' ' |
|
|
|
|
|
|
|
: ` DEFAULT ''`; |
|
|
|
addNewColumnQuery += n.rqd ? ` NOT NULL` : ' '; |
|
|
|
addNewColumnQuery += n.rqd ? ` NOT NULL` : ' '; |
|
|
|
addNewColumnQuery = this.genQuery(`ALTER TABLE ?? ${addNewColumnQuery};`, [t], shouldSanitize); |
|
|
|
addNewColumnQuery = this.genQuery( |
|
|
|
|
|
|
|
`ALTER TABLE ?? ${addNewColumnQuery};`, |
|
|
|
|
|
|
|
[t], |
|
|
|
|
|
|
|
shouldSanitize |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
let updateNewColumnQuery = this.genQuery(`UPDATE ?? SET ?? = ??;`, [t, n.cn, `${o.cno}_nc_${suffix}`], shouldSanitize); |
|
|
|
let updateNewColumnQuery = this.genQuery( |
|
|
|
|
|
|
|
`UPDATE ?? SET ?? = ??;`, |
|
|
|
|
|
|
|
[t, n.cn, `${o.cno}_nc_${suffix}`], |
|
|
|
|
|
|
|
shouldSanitize |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
let dropOldColumnQuery = this.genQuery(`ALTER TABLE ?? DROP COLUMN ??;`, [t, `${o.cno}_nc_${suffix}`], shouldSanitize); |
|
|
|
let dropOldColumnQuery = this.genQuery( |
|
|
|
|
|
|
|
`ALTER TABLE ?? DROP COLUMN ??;`, |
|
|
|
|
|
|
|
[t, `${o.cno}_nc_${suffix}`], |
|
|
|
|
|
|
|
shouldSanitize |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
query = `${backupOldColumnQuery}${addNewColumnQuery}${updateNewColumnQuery}${dropOldColumnQuery}`; |
|
|
|
query = `${backupOldColumnQuery}${addNewColumnQuery}${updateNewColumnQuery}${dropOldColumnQuery}`; |
|
|
|
} else if (change === 0) { |
|
|
|
} else if (change === 0) { |
|
|
|
query = existingQuery ? ',' : ''; |
|
|
|
query = existingQuery ? ',' : ''; |
|
|
|
query += this.genQuery(`?? ${n.dt}`, [n.cn], shouldSanitize); |
|
|
|
query += this.genQuery(`?? ${n.dt}`, [n.cn], shouldSanitize); |
|
|
|
query += n.dtxp && n.dt !== 'text' ? `(${n.dtxp})` : ''; |
|
|
|
query += n.dtxp && n.dt !== 'text' ? `(${n.dtxp})` : ''; |
|
|
|
query += n.cdf |
|
|
|
query += n.cdf ? ` DEFAULT ${n.cdf}` : ' '; |
|
|
|
? ` DEFAULT ${n.cdf}` |
|
|
|
|
|
|
|
: ' '; |
|
|
|
|
|
|
|
query += n.rqd ? ` NOT NULL` : ' '; |
|
|
|
query += n.rqd ? ` NOT NULL` : ' '; |
|
|
|
} else if (change === 1) { |
|
|
|
} else if (change === 1) { |
|
|
|
shouldSanitize = true; |
|
|
|
shouldSanitize = true; |
|
|
|
query += this.genQuery(` ADD ?? ${n.dt}`, [n.cn], shouldSanitize); |
|
|
|
query += this.genQuery(` ADD ?? ${n.dt}`, [n.cn], shouldSanitize); |
|
|
|
query += n.dtxp && n.dt !== 'text' ? `(${n.dtxp})` : ''; |
|
|
|
query += n.dtxp && n.dt !== 'text' ? `(${n.dtxp})` : ''; |
|
|
|
query += n.cdf |
|
|
|
query += n.cdf ? ` DEFAULT ${n.cdf}` : !n.rqd ? ' ' : ` DEFAULT ''`; |
|
|
|
? ` DEFAULT ${n.cdf}` |
|
|
|
|
|
|
|
: !n.rqd ? ' ' : ` DEFAULT ''`; |
|
|
|
|
|
|
|
query += n.rqd ? ` NOT NULL` : ' '; |
|
|
|
query += n.rqd ? ` NOT NULL` : ' '; |
|
|
|
query = this.genQuery(`ALTER TABLE ?? ${query};`, [t], shouldSanitize); |
|
|
|
query = this.genQuery(`ALTER TABLE ?? ${query};`, [t], shouldSanitize); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|