mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 07:56:28 +00:00
fixes sqlite autoincrement column creation
This commit is contained in:
@@ -244,16 +244,7 @@ export class SqlDumper implements AlterProcessor {
|
|||||||
this.put('%i ', col.columnName);
|
this.put('%i ', col.columnName);
|
||||||
this.columnDefinition(col);
|
this.columnDefinition(col);
|
||||||
});
|
});
|
||||||
if (table.primaryKey) {
|
this.createTablePrimaryKeyCore(table);
|
||||||
this.put(',&n');
|
|
||||||
if (table.primaryKey.constraintName) {
|
|
||||||
this.put('^constraint %i', table.primaryKey.constraintName);
|
|
||||||
}
|
|
||||||
this.put(
|
|
||||||
' ^primary ^key (%,i)',
|
|
||||||
table.primaryKey.columns.map(x => x.columnName)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
(table.foreignKeys || []).forEach(fk => {
|
(table.foreignKeys || []).forEach(fk => {
|
||||||
this.put(',&n');
|
this.put(',&n');
|
||||||
@@ -275,6 +266,19 @@ export class SqlDumper implements AlterProcessor {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createTablePrimaryKeyCore(table: TableInfo) {
|
||||||
|
if (table.primaryKey) {
|
||||||
|
this.put(',&n');
|
||||||
|
if (table.primaryKey.constraintName) {
|
||||||
|
this.put('^constraint %i', table.primaryKey.constraintName);
|
||||||
|
}
|
||||||
|
this.put(
|
||||||
|
' ^primary ^key (%,i)',
|
||||||
|
table.primaryKey.columns.map(x => x.columnName)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
createForeignKeyFore(fk: ForeignKeyInfo) {
|
createForeignKeyFore(fk: ForeignKeyInfo) {
|
||||||
if (fk.constraintName != null) this.put('^constraint %i ', fk.constraintName);
|
if (fk.constraintName != null) this.put('^constraint %i ', fk.constraintName);
|
||||||
this.put(
|
this.put(
|
||||||
|
|||||||
@@ -18,7 +18,23 @@ class Dumper extends SqlDumper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
selectScopeIdentity() {
|
selectScopeIdentity() {
|
||||||
this.put('^select last_insert_rowid()')
|
this.put('^select last_insert_rowid()');
|
||||||
|
}
|
||||||
|
|
||||||
|
columnDefinition(column, flags) {
|
||||||
|
if (column.dataType && column.dataType.toLowerCase().includes('int') && column.notNull && column.autoIncrement) {
|
||||||
|
this.put('^integer ^primary ^key ^autoincrement');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
super.columnDefinition(column, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
createTablePrimaryKeyCore(table) {
|
||||||
|
const column = table.columns.find((x) => x.autoIncrement);
|
||||||
|
if (column && column.dataType && column.dataType.toLowerCase().includes('int') && column.notNull) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
super.createTablePrimaryKeyCore(table);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user