One failure left for MSSQL
This commit is contained in:
parent
7d8cadb47f
commit
9da10c790e
|
@ -49,6 +49,7 @@ export async function save(
|
|||
builderSocket?.emitDatasourceUpdate(ctx, datasource)
|
||||
return table
|
||||
} catch (err: any) {
|
||||
throw err
|
||||
if (err instanceof Error) {
|
||||
ctx.throw(400, err.message)
|
||||
} else {
|
||||
|
|
|
@ -28,11 +28,11 @@ const { basicTable } = setup.structures
|
|||
const ISO_REGEX_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/
|
||||
|
||||
describe.each([
|
||||
["internal", undefined],
|
||||
[DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)],
|
||||
[DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)],
|
||||
// [DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)],
|
||||
[DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)],
|
||||
// ["internal", undefined],
|
||||
// [DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)],
|
||||
// [DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)],
|
||||
[DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)],
|
||||
// [DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)],
|
||||
])("/tables (%s)", (_, dsProvider) => {
|
||||
let isInternal: boolean
|
||||
let datasource: Datasource | undefined
|
||||
|
@ -114,7 +114,7 @@ describe.each([
|
|||
expect(events.table.updated).toHaveBeenCalledWith(updatedTable)
|
||||
})
|
||||
|
||||
it("updates all the row fields for a table when a schema key is renamed", async () => {
|
||||
it.only("updates all the row fields for a table when a schema key is renamed", async () => {
|
||||
const testTable = await config.api.table.save(basicTable(datasource))
|
||||
await config.createLegacyView({
|
||||
name: "TestView",
|
||||
|
@ -130,24 +130,14 @@ describe.each([
|
|||
})
|
||||
|
||||
const updatedTable = await config.api.table.save({
|
||||
_id: testTable._id,
|
||||
_rev: testTable._rev,
|
||||
type: "table",
|
||||
sourceId: datasource ? datasource._id! : INTERNAL_TABLE_SOURCE_ID,
|
||||
sourceType: isInternal
|
||||
? TableSourceType.INTERNAL
|
||||
: TableSourceType.EXTERNAL,
|
||||
name: "TestTable",
|
||||
...testTable,
|
||||
_rename: {
|
||||
old: "name",
|
||||
updated: "updatedName",
|
||||
},
|
||||
schema: {
|
||||
updatedName: { type: FieldType.STRING, name: "updatedName" },
|
||||
},
|
||||
})
|
||||
|
||||
expect(updatedTable.name).toEqual("TestTable")
|
||||
expect(updatedTable.name).toEqual(testTable.name)
|
||||
|
||||
const res = await config.api.row.get(testTable._id!, testRow._id!)
|
||||
expect(res.updatedName).toEqual("test")
|
||||
|
|
|
@ -229,6 +229,7 @@ class SqlTableQueryBuilder {
|
|||
bindings: [],
|
||||
}
|
||||
}
|
||||
|
||||
query = buildUpdateTable(
|
||||
client,
|
||||
json.table,
|
||||
|
@ -236,6 +237,27 @@ class SqlTableQueryBuilder {
|
|||
json.meta.table,
|
||||
json.meta.renamed!
|
||||
)
|
||||
|
||||
// renameColumn for SQL Server returns a parameterised `sp_rename` query,
|
||||
// which is not supported by SQL Server and gives a syntax error.
|
||||
if (this.sqlClient === SqlClient.MS_SQL && json.meta.renamed) {
|
||||
const oldColumn = json.meta.renamed.old
|
||||
const updatedColumn = json.meta.renamed.updated
|
||||
const tableName = schemaName
|
||||
? `${schemaName}.${json.table.name}`
|
||||
: `${json.table.name}`
|
||||
const sql = query.toSQL()
|
||||
if (Array.isArray(sql)) {
|
||||
for (const query of sql) {
|
||||
if (query.sql.startsWith("exec sp_rename")) {
|
||||
query.sql = `exec sp_rename '${tableName}.${oldColumn}', '${updatedColumn}', 'COLUMN'`
|
||||
query.bindings = []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sql
|
||||
}
|
||||
break
|
||||
case Operation.DELETE_TABLE:
|
||||
query = buildDeleteTable(client, json.table)
|
||||
|
|
Loading…
Reference in New Issue