@nuxodin/item 0.6.11 → 0.6.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -30,10 +30,12 @@ function emittable(prop, isSoloPk) {
|
|
|
30
30
|
return out
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
function createBody(fields, primaries) {
|
|
33
|
+
function createBody(table, fields, primaries) {
|
|
34
34
|
const solo = soloIntPrimary(fields, primaries)
|
|
35
35
|
const cols = fields.map(([n, f]) => {
|
|
36
36
|
const isPk = n === solo
|
|
37
|
+
if (f['x-autoincrement'] && !isPk)
|
|
38
|
+
console.warn(`Skip AUTOINCREMENT ${table}.${n}: SQLite auto-increments only a sole INTEGER PRIMARY KEY — nothing fills this column`)
|
|
37
39
|
// Only `INTEGER PRIMARY KEY` is the rowid alias, and AUTOINCREMENT is legal nowhere else —
|
|
38
40
|
// so a boolean key keeps the integer spelling, which SQLite would otherwise reject.
|
|
39
41
|
let def = toFieldDef(n, isPk ? { ...f, type: 'integer' } : f)
|
|
@@ -99,7 +101,7 @@ export async function schemaToDb(schema, query, { force = false, patch = false }
|
|
|
99
101
|
const primaries = fields.filter(([, f]) => f['x-index'] === 'primary').map(([n]) => n)
|
|
100
102
|
|
|
101
103
|
if (!currTables.includes(table)) {
|
|
102
|
-
stmts.push(`CREATE TABLE ${quoteId(table)} (\n${createBody(fields, primaries)}\n);`)
|
|
104
|
+
stmts.push(`CREATE TABLE ${quoteId(table)} (\n${createBody(table, fields, primaries)}\n);`)
|
|
103
105
|
stmts.push(...indexStatements(table, fields, primaries))
|
|
104
106
|
} else {
|
|
105
107
|
const currFields = new Map(tableFields(current.properties[table]))
|
|
@@ -116,7 +118,7 @@ export async function schemaToDb(schema, query, { force = false, patch = false }
|
|
|
116
118
|
const keep = fields.map(([n]) => n).filter(n => currFields.has(n))
|
|
117
119
|
const colsList = keep.map(quoteId).join(', ')
|
|
118
120
|
|
|
119
|
-
stmts.push(`CREATE TABLE ${quoteId(tmp)} (\n${createBody(fields, primaries)}\n);`)
|
|
121
|
+
stmts.push(`CREATE TABLE ${quoteId(tmp)} (\n${createBody(table, fields, primaries)}\n);`)
|
|
120
122
|
if (keep.length) stmts.push(`INSERT INTO ${quoteId(tmp)} (${colsList}) SELECT ${colsList} FROM ${quoteId(table)};`)
|
|
121
123
|
stmts.push(`DROP TABLE ${quoteId(table)};`)
|
|
122
124
|
stmts.push(`ALTER TABLE ${quoteId(tmp)} RENAME TO ${quoteId(table)};`)
|