mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-16 18:43:10 -06:00
Tweaks
This commit is contained in:
parent
1fb83b3463
commit
e8b52ff95d
|
|
@ -5,8 +5,6 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/lib/pq"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var renameTableMappings = map[string]string{
|
var renameTableMappings = map[string]string{
|
||||||
|
|
@ -43,8 +41,7 @@ func UpRenameTables(ctx context.Context, tx *sql.Tx) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
q := fmt.Sprintf(
|
q := fmt.Sprintf(
|
||||||
"ALTER TABLE %s RENAME TO %s;",
|
"ALTER TABLE %s RENAME TO %s;", old, new,
|
||||||
pq.QuoteIdentifier(old), pq.QuoteIdentifier(new),
|
|
||||||
)
|
)
|
||||||
if _, err := tx.ExecContext(ctx, q); err != nil {
|
if _, err := tx.ExecContext(ctx, q); err != nil {
|
||||||
return fmt.Errorf("rename table %q to %q error: %w", old, new, err)
|
return fmt.Errorf("rename table %q to %q error: %w", old, new, err)
|
||||||
|
|
@ -61,7 +58,7 @@ func UpRenameTables(ctx context.Context, tx *sql.Tx) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
query = strings.Replace(query, old, new, 1)
|
query = strings.Replace(query, old, new, 1)
|
||||||
if _, err := tx.ExecContext(ctx, "DROP INDEX %s;", pq.QuoteIdentifier(old)); err != nil {
|
if _, err := tx.ExecContext(ctx, "DROP INDEX %s;", old); err != nil {
|
||||||
return fmt.Errorf("drop index %q to %q error: %w", old, new, err)
|
return fmt.Errorf("drop index %q to %q error: %w", old, new, err)
|
||||||
}
|
}
|
||||||
if _, err := tx.ExecContext(ctx, query); err != nil {
|
if _, err := tx.ExecContext(ctx, query); err != nil {
|
||||||
|
|
@ -84,8 +81,7 @@ func DownRenameTables(ctx context.Context, tx *sql.Tx) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
q := fmt.Sprintf(
|
q := fmt.Sprintf(
|
||||||
"ALTER TABLE %s RENAME TO %s;",
|
"ALTER TABLE %s RENAME TO %s;", new, old,
|
||||||
pq.QuoteIdentifier(new), pq.QuoteIdentifier(old),
|
|
||||||
)
|
)
|
||||||
if _, err := tx.ExecContext(ctx, q); err != nil {
|
if _, err := tx.ExecContext(ctx, q); err != nil {
|
||||||
return fmt.Errorf("rename table %q to %q error: %w", new, old, err)
|
return fmt.Errorf("rename table %q to %q error: %w", new, old, err)
|
||||||
|
|
@ -102,7 +98,7 @@ func DownRenameTables(ctx context.Context, tx *sql.Tx) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
query = strings.Replace(query, new, old, 1)
|
query = strings.Replace(query, new, old, 1)
|
||||||
if _, err := tx.ExecContext(ctx, "DROP INDEX %s;", pq.QuoteIdentifier(new)); err != nil {
|
if _, err := tx.ExecContext(ctx, "DROP INDEX %s;", new); err != nil {
|
||||||
return fmt.Errorf("drop index %q to %q error: %w", new, old, err)
|
return fmt.Errorf("drop index %q to %q error: %w", new, old, err)
|
||||||
}
|
}
|
||||||
if _, err := tx.ExecContext(ctx, query); err != nil {
|
if _, err := tx.ExecContext(ctx, query); err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue