Adding missed files

This commit is contained in:
Jesús Espino 2020-10-16 22:27:16 +02:00
parent 3c15957e3d
commit 61cdfecef9
5 changed files with 63 additions and 0 deletions

View 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
}

View file

@ -0,0 +1 @@
DROP TABLE blocks;

View file

@ -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)
);

View file

@ -0,0 +1 @@
DROP TABLE blocks;

View file

@ -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)
);