MM-26514: Fix ALTER PRIMARY KEY migration for Postgres <9.3 (#14912)
* MM-26514: Fix ALTER PRIMARY KEY migration for Postgres <9.3 We work around the lack of LATERAL keyword by making the query separately. * Complete full WHERE clause just to be sure
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
4bfad26614
Коммит
dd40d59c84
@@ -786,7 +786,8 @@ func (ss *SqlSupplier) AlterPrimaryKey(tableName string, columnNames []string) b
|
|||||||
var currentPrimaryKey string
|
var currentPrimaryKey string
|
||||||
var err error
|
var err error
|
||||||
// get the current primary key as a comma separated list of columns
|
// get the current primary key as a comma separated list of columns
|
||||||
if ss.DriverName() == model.DATABASE_DRIVER_MYSQL {
|
switch ss.DriverName() {
|
||||||
|
case model.DATABASE_DRIVER_MYSQL:
|
||||||
query := `
|
query := `
|
||||||
SELECT GROUP_CONCAT(column_name ORDER BY seq_in_index) AS PK
|
SELECT GROUP_CONCAT(column_name ORDER BY seq_in_index) AS PK
|
||||||
FROM
|
FROM
|
||||||
@@ -798,13 +799,13 @@ func (ss *SqlSupplier) AlterPrimaryKey(tableName string, columnNames []string) b
|
|||||||
GROUP BY
|
GROUP BY
|
||||||
index_name`
|
index_name`
|
||||||
currentPrimaryKey, err = ss.GetMaster().SelectStr(query, tableName)
|
currentPrimaryKey, err = ss.GetMaster().SelectStr(query, tableName)
|
||||||
} else if ss.DriverName() == model.DATABASE_DRIVER_POSTGRES {
|
case model.DATABASE_DRIVER_POSTGRES:
|
||||||
query := `
|
query := `
|
||||||
SELECT string_agg(a.attname, ',') AS pk
|
SELECT string_agg(a.attname, ',') AS pk
|
||||||
FROM
|
FROM
|
||||||
pg_constraint AS c
|
pg_constraint AS c
|
||||||
CROSS JOIN LATERAL
|
CROSS JOIN
|
||||||
UNNEST(c.conkey) AS cols(colnum)
|
(SELECT unnest(conkey) FROM pg_constraint WHERE conrelid='` + strings.ToLower(tableName) + `'::REGCLASS AND contype='p') AS cols(colnum)
|
||||||
INNER JOIN
|
INNER JOIN
|
||||||
pg_attribute AS a ON a.attrelid = c.conrelid
|
pg_attribute AS a ON a.attrelid = c.conrelid
|
||||||
AND cols.colnum = a.attnum
|
AND cols.colnum = a.attnum
|
||||||
@@ -812,7 +813,7 @@ func (ss *SqlSupplier) AlterPrimaryKey(tableName string, columnNames []string) b
|
|||||||
c.contype = 'p'
|
c.contype = 'p'
|
||||||
AND c.conrelid = '` + strings.ToLower(tableName) + `'::REGCLASS`
|
AND c.conrelid = '` + strings.ToLower(tableName) + `'::REGCLASS`
|
||||||
currentPrimaryKey, err = ss.GetMaster().SelectStr(query)
|
currentPrimaryKey, err = ss.GetMaster().SelectStr(query)
|
||||||
} else if ss.DriverName() == model.DATABASE_DRIVER_SQLITE {
|
case model.DATABASE_DRIVER_SQLITE:
|
||||||
// SQLite doesn't support altering primary key
|
// SQLite doesn't support altering primary key
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user