mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 12:43:58 +00:00
create fk script
This commit is contained in:
@@ -28,6 +28,11 @@ class SqlDumper {
|
|||||||
this.putRaw(this.dialect.quoteIdentifier(value));
|
this.putRaw(this.dialect.quoteIdentifier(value));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "k":
|
||||||
|
{
|
||||||
|
this.putRaw(value.toUpperCase());
|
||||||
|
}
|
||||||
|
break;
|
||||||
case "f":
|
case "f":
|
||||||
{
|
{
|
||||||
const { schemaName, pureName } = value;
|
const { schemaName, pureName } = value;
|
||||||
@@ -188,21 +193,19 @@ class SqlDumper {
|
|||||||
table.primaryKey.columns.map(x => x.columnName)
|
table.primaryKey.columns.map(x => x.columnName)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// foreach (var cnt in table.ForeignKeys)
|
table.foreignKeys.forEach(fk => {
|
||||||
// {
|
this.put(",&n");
|
||||||
// if (!first) Put(", &n");
|
this.createForeignKeyFore(fk);
|
||||||
// first = false;
|
});
|
||||||
// CreateForeignKeyCore(cnt);
|
|
||||||
// }
|
|
||||||
// foreach (var cnt in table.Uniques)
|
// foreach (var cnt in table.Uniques)
|
||||||
// {
|
// {
|
||||||
// if (!first) Put(", &n");
|
// if (!first) this.put(", &n");
|
||||||
// first = false;
|
// first = false;
|
||||||
// CreateUniqueCore(cnt);
|
// CreateUniqueCore(cnt);
|
||||||
// }
|
// }
|
||||||
// foreach (var cnt in table.Checks)
|
// foreach (var cnt in table.Checks)
|
||||||
// {
|
// {
|
||||||
// if (!first) Put(", &n");
|
// if (!first) this.put(", &n");
|
||||||
// first = false;
|
// first = false;
|
||||||
// CreateCheckCore(cnt);
|
// CreateCheckCore(cnt);
|
||||||
// }
|
// }
|
||||||
@@ -213,6 +216,20 @@ class SqlDumper {
|
|||||||
// CreateIndex(ix);
|
// CreateIndex(ix);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @param fk {import('@dbgate/types').ForeignKeyInfo} */
|
||||||
|
createForeignKeyFore(fk) {
|
||||||
|
if (fk.constraintName != null)
|
||||||
|
this.put("^constraint %i ", fk.constraintName);
|
||||||
|
this.put(
|
||||||
|
"^foreign ^key (%,i) ^references %f (%,i)",
|
||||||
|
fk.columns.map(x => x.columnName),
|
||||||
|
{ schemaName: fk.refSchemaName, pureName: fk.refTableName },
|
||||||
|
fk.columns.map(x => x.refColumnName)
|
||||||
|
);
|
||||||
|
if (fk.deleteAction) this.put(" ^on ^delete %k", fk.deleteAction);
|
||||||
|
if (fk.updateAction) this.put(" ^on ^update %k", fk.updateAction);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = SqlDumper;
|
module.exports = SqlDumper;
|
||||||
|
|||||||
Reference in New Issue
Block a user