mirror of
https://github.com/pomerium/pomerium.git
synced 2025-06-27 06:58:13 +02:00
postgres: use CTE and GENERATED version number instead of serialized transaction (#3408)
* postgres: use CTE and GENERATED version number instead of serialized transaction * update server version * fix indexing CIDRs
This commit is contained in:
parent
a7bd284b52
commit
a2d5d8062b
5 changed files with 81 additions and 82 deletions
|
@ -77,6 +77,41 @@ var migrations = []func(context.Context, pgx.Tx) error{
|
|||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
2: func(ctx context.Context, tx pgx.Tx) error {
|
||||
serverVersion := uint64(cryptutil.NewRandomUInt32())
|
||||
_, err := tx.Exec(ctx, `
|
||||
UPDATE `+schemaName+`.`+migrationInfoTableName+`
|
||||
SET server_version = $1
|
||||
`, serverVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = tx.Exec(ctx, `
|
||||
DELETE FROM `+schemaName+`.`+recordChangesTableName+`
|
||||
`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = tx.Exec(ctx, `
|
||||
DELETE FROM `+schemaName+`.`+recordsTableName+`
|
||||
`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = tx.Exec(ctx, `
|
||||
ALTER TABLE `+schemaName+`.`+recordChangesTableName+`
|
||||
ALTER COLUMN version
|
||||
ADD GENERATED BY DEFAULT AS IDENTITY
|
||||
`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue