Skip to content

Commit

Permalink
fix sql issues from mfridman
Browse files Browse the repository at this point in the history
  • Loading branch information
asmyasnikov committed Oct 23, 2023
1 parent 898d81d commit 3dba2c8
Showing 1 changed file with 25 additions and 40 deletions.
65 changes: 25 additions & 40 deletions internal/dialect/dialectquery/ydb.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,41 @@ type Ydb struct{}
var _ Querier = (*Ydb)(nil)

func (c *Ydb) CreateTable(tableName string) string {
return fmt.Sprintf(`
CREATE TABLE %s (
version_id Uint64,
is_applied Bool,
tstamp Timestamp,
PRIMARY KEY(version_id)
);`,
tableName,
)
q := `CREATE TABLE %s (
version_id Uint64,
is_applied Bool,
tstamp Timestamp,
PRIMARY KEY(version_id)
)`
return fmt.Sprintf(q, tableName)
}

func (c *Ydb) InsertVersion(tableName string) string {
return fmt.Sprintf(`
UPSERT INTO %s (
version_id,
is_applied,
tstamp
) VALUES (
CAST($1 AS Uint64),
$2,
CurrentUtcTimestamp()
);`,
tableName,
)
q := `INSERT INTO %s (
version_id,
is_applied,
tstamp
) VALUES (
CAST($1 AS Uint64),
$2,
CurrentUtcTimestamp()
)`
return fmt.Sprintf(q, tableName)
}

func (c *Ydb) DeleteVersion(tableName string) string {
return fmt.Sprintf(`
DELETE FROM %s
WHERE version_id = $1;`,
tableName,
)
q := `DELETE FROM %s WHERE version_id = $1`
return fmt.Sprintf(q, tableName)
}

func (c *Ydb) GetMigrationByVersion(tableName string) string {
return fmt.Sprintf(`
SELECT tstamp, is_applied
FROM %s
WHERE version_id = $1
ORDER BY tstamp DESC LIMIT 1`,
tableName,
)
q := `SELECT tstamp, is_applied FROM %s WHERE version_id = $1 ORDER BY tstamp DESC LIMIT 1`
return fmt.Sprintf(q, tableName)
}

func (c *Ydb) ListMigrations(tableName string) string {
return fmt.Sprintf(`--!syntax_pg
SELECT version_id, is_applied
FROM %s
ORDER BY tstamp DESC`,
tableName,
)
q := `--!syntax_pg
SELECT version_id, is_applied FROM %s ORDER BY tstamp DESC`
return fmt.Sprintf(q, tableName)
}

0 comments on commit 3dba2c8

Please sign in to comment.