1
0
Fork 0
mirror of synced 2024-08-01 11:21:41 +12:00

One failure left for MSSQL

This commit is contained in:
Sam Rose 2024-04-05 17:47:55 +01:00
parent 7d8cadb47f
commit 9da10c790e
No known key found for this signature in database
3 changed files with 31 additions and 18 deletions

View file

@ -49,6 +49,7 @@ export async function save(
builderSocket?.emitDatasourceUpdate(ctx, datasource) builderSocket?.emitDatasourceUpdate(ctx, datasource)
return table return table
} catch (err: any) { } catch (err: any) {
throw err
if (err instanceof Error) { if (err instanceof Error) {
ctx.throw(400, err.message) ctx.throw(400, err.message)
} else { } else {

View file

@ -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$/ const ISO_REGEX_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/
describe.each([ describe.each([
["internal", undefined], // ["internal", undefined],
[DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)], // [DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)],
[DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)], // [DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)],
// [DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)], [DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)],
[DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)], // [DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)],
])("/tables (%s)", (_, dsProvider) => { ])("/tables (%s)", (_, dsProvider) => {
let isInternal: boolean let isInternal: boolean
let datasource: Datasource | undefined let datasource: Datasource | undefined
@ -114,7 +114,7 @@ describe.each([
expect(events.table.updated).toHaveBeenCalledWith(updatedTable) 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)) const testTable = await config.api.table.save(basicTable(datasource))
await config.createLegacyView({ await config.createLegacyView({
name: "TestView", name: "TestView",
@ -130,24 +130,14 @@ describe.each([
}) })
const updatedTable = await config.api.table.save({ const updatedTable = await config.api.table.save({
_id: testTable._id, ...testTable,
_rev: testTable._rev,
type: "table",
sourceId: datasource ? datasource._id! : INTERNAL_TABLE_SOURCE_ID,
sourceType: isInternal
? TableSourceType.INTERNAL
: TableSourceType.EXTERNAL,
name: "TestTable",
_rename: { _rename: {
old: "name", old: "name",
updated: "updatedName", 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!) const res = await config.api.row.get(testTable._id!, testRow._id!)
expect(res.updatedName).toEqual("test") expect(res.updatedName).toEqual("test")

View file

@ -229,6 +229,7 @@ class SqlTableQueryBuilder {
bindings: [], bindings: [],
} }
} }
query = buildUpdateTable( query = buildUpdateTable(
client, client,
json.table, json.table,
@ -236,6 +237,27 @@ class SqlTableQueryBuilder {
json.meta.table, json.meta.table,
json.meta.renamed! 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 break
case Operation.DELETE_TABLE: case Operation.DELETE_TABLE:
query = buildDeleteTable(client, json.table) query = buildDeleteTable(client, json.table)