Skip to content

Commit

Permalink
pg: remove old pseudo-upgrade
Browse files Browse the repository at this point in the history
A pseudo-upgrade was added prior to the first release and prior to
schema versioning that would create the matches.forgiven column
if it does not exist.  It has existed in the CREATE TABLE statement
since first release so this ALTER TABLE is always a no-op that just
results in a logged NOTICE:

[DBG] DB: pq: NOTICE (42701) - duplicate_column: column "forgiven" of relation "matches" already exists, skipping

The comments around this indicate the same, that this should have been
removed when actual upgrades were implemented. Schema v1 does
indeed include this forgiven column, and this change can thus remove
the ALTER TABLE statement that tries to re-add it on every startup.
  • Loading branch information
chappjc committed Oct 14, 2021
1 parent d6a9c33 commit dad4a2e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
3 changes: 0 additions & 3 deletions server/db/driver/pg/internal/matches.go
Expand Up @@ -62,9 +62,6 @@ const (
RetrieveMatchStatsByEpoch = `SELECT quantity, rate, takerSell FROM %s
WHERE takerSell IS NOT NULL AND epochIdx = $1 AND epochDur = $2;`

AddMatchesForgivenColumn = `ALTER TABLE %s
ADD COLUMN IF NOT EXISTS forgiven BOOL;`

RetrieveSwapData = `SELECT status, sigMatchAckMaker, sigMatchAckTaker,
aContractCoinID, aContract, aContractTime, bSigAckOfAContract,
bContractCoinID, bContract, bContractTime, aSigAckOfBContract,
Expand Down
25 changes: 5 additions & 20 deletions server/db/driver/pg/markets.go
Expand Up @@ -59,19 +59,12 @@ func newMarket(db *sql.DB, marketsTableName string, mkt *dex.MarketInfo) error {
return nil
}

// Basic idempotent table alteration queries for existing markets tables with a
// printf specifier for full name of the targeted table. Remove this when scheme
// versioning and upgrades are implemented (and v1 has the changes already).
var marketTablesUpdates = map[string]string{
matchesTableName: internal.AddMatchesForgivenColumn,
}

func createMarketTables(db *sql.DB, marketUID string) error {
created, err := createSchema(db, marketUID)
newMarket, err := createSchema(db, marketUID)
if err != nil {
return err
}
if created {
if newMarket {
log.Debugf("Created new market schema %q", marketUID)
} else {
log.Tracef("Market schema %q already exists.", marketUID)
Expand All @@ -82,17 +75,9 @@ func createMarketTables(db *sql.DB, marketUID string) error {
if err != nil {
return err
}
if newTable {
if !created {
log.Warnf(`Created missing table "%s" for existing market %s.`,
c.name, marketUID)
}
} else if update, found := marketTablesUpdates[c.name]; found {
// Remove this with actual upgrades.
nameSpacedTable := marketUID + "." + c.name
if _, err = db.Exec(fmt.Sprintf(update, nameSpacedTable)); err != nil {
return fmt.Errorf("failed to update table %v: %w", nameSpacedTable, err)
}
if newTable && !newMarket {
log.Warnf(`Created missing table "%s" for existing market %s.`,
c.name, marketUID)
}
}

Expand Down

0 comments on commit dad4a2e

Please sign in to comment.