Adding missed files
This commit is contained in:
parent
3c15957e3d
commit
61cdfecef9
5 changed files with 63 additions and 0 deletions
35
server/services/store/sqlstore/migrate.go
Normal file
35
server/services/store/sqlstore/migrate.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package sqlstore
|
||||
|
||||
import (
|
||||
"github.com/golang-migrate/migrate/v4"
|
||||
"github.com/golang-migrate/migrate/v4/database"
|
||||
"github.com/golang-migrate/migrate/v4/database/postgres"
|
||||
"github.com/golang-migrate/migrate/v4/database/sqlite3"
|
||||
_ "github.com/golang-migrate/migrate/v4/source/file"
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
func (s *SQLStore) Migrate() error {
|
||||
var driver database.Driver
|
||||
var err error
|
||||
var migrationsDir string
|
||||
if s.dbType == "sqlite3" {
|
||||
driver, err = sqlite3.WithInstance(s.db, &sqlite3.Config{})
|
||||
migrationsDir = "file://./server/services/store/sqlstore/migrations/sqlite"
|
||||
}
|
||||
if s.dbType == "postgres" {
|
||||
driver, err = postgres.WithInstance(s.db, &postgres.Config{})
|
||||
migrationsDir = "file://./server/services/store/sqlstore/migrations/postgres"
|
||||
}
|
||||
m, err := migrate.NewWithDatabaseInstance(migrationsDir, s.dbType, driver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// defer m.Close()
|
||||
|
||||
err = m.Up()
|
||||
if err != nil && err != migrate.ErrNoChange {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
DROP TABLE blocks;
|
|
@ -0,0 +1,13 @@
|
|||
CREATE TABLE IF NOT EXISTS blocks (
|
||||
id VARCHAR(36),
|
||||
insert_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
parent_id VARCHAR(36),
|
||||
schema BIGINT,
|
||||
type TEXT,
|
||||
title TEXT,
|
||||
fields TEXT,
|
||||
create_at BIGINT,
|
||||
update_at BIGINT,
|
||||
delete_at BIGINT,
|
||||
PRIMARY KEY (id, insert_at)
|
||||
);
|
|
@ -0,0 +1 @@
|
|||
DROP TABLE blocks;
|
|
@ -0,0 +1,13 @@
|
|||
CREATE TABLE IF NOT EXISTS blocks (
|
||||
id VARCHAR(36),
|
||||
insert_at DATETIME NOT NULL DEFAULT(STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),
|
||||
parent_id VARCHAR(36),
|
||||
schema BIGINT,
|
||||
type TEXT,
|
||||
title TEXT,
|
||||
fields TEXT,
|
||||
create_at BIGINT,
|
||||
update_at BIGINT,
|
||||
delete_at BIGINT,
|
||||
PRIMARY KEY (id, insert_at)
|
||||
);
|
Loading…
Reference in a new issue