vertica.go

 1package dialectquery
 2
 3import "fmt"
 4
 5type Vertica struct{}
 6
 7var _ Querier = (*Vertica)(nil)
 8
 9func (v *Vertica) CreateTable(tableName string) string {
10	q := `CREATE TABLE %s (
11		id identity(1,1) NOT NULL,
12		version_id bigint NOT NULL,
13		is_applied boolean NOT NULL,
14		tstamp timestamp NULL default now(),
15		PRIMARY KEY(id)
16	)`
17	return fmt.Sprintf(q, tableName)
18}
19
20func (v *Vertica) InsertVersion(tableName string) string {
21	q := `INSERT INTO %s (version_id, is_applied) VALUES (?, ?)`
22	return fmt.Sprintf(q, tableName)
23}
24
25func (v *Vertica) DeleteVersion(tableName string) string {
26	q := `DELETE FROM %s WHERE version_id=?`
27	return fmt.Sprintf(q, tableName)
28}
29
30func (v *Vertica) GetMigrationByVersion(tableName string) string {
31	q := `SELECT tstamp, is_applied FROM %s WHERE version_id=? ORDER BY tstamp DESC LIMIT 1`
32	return fmt.Sprintf(q, tableName)
33}
34
35func (v *Vertica) ListMigrations(tableName string) string {
36	q := `SELECT version_id, is_applied from %s ORDER BY id DESC`
37	return fmt.Sprintf(q, tableName)
38}
39
40func (v *Vertica) GetLatestVersion(tableName string) string {
41	q := `SELECT MAX(version_id) FROM %s`
42	return fmt.Sprintf(q, tableName)
43}