本文整理匯總了Golang中github.com/flynn/flynn/pkg/postgres.NewMigrations函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewMigrations函數的具體用法?Golang NewMigrations怎麽用?Golang NewMigrations使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewMigrations函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewPostgresFilesystem
func NewPostgresFilesystem(db *sql.DB) (Filesystem, error) {
m := postgres.NewMigrations()
m.Add(1,
`CREATE TABLE files (
file_id oid PRIMARY KEY DEFAULT lo_create(0),
name text UNIQUE NOT NULL,
size bigint,
type text,
digest text,
created_at timestamp with time zone NOT NULL DEFAULT current_timestamp
);`,
`CREATE FUNCTION delete_file() RETURNS TRIGGER AS $$
BEGIN
PERFORM lo_unlink(OLD.file_id);
RETURN NULL;
END;
$$ LANGUAGE plpgsql;`,
`CREATE TRIGGER delete_file
AFTER DELETE ON files
FOR EACH ROW EXECUTE PROCEDURE delete_file();`,
)
return &PostgresFilesystem{db: db}, m.Migrate(db)
}
示例2: NewPostgresFilesystem
func NewPostgresFilesystem(db *sql.DB) (Filesystem, error) {
m := postgres.NewMigrations()
m.Add(1,
`CREATE TABLE files (
file_id oid PRIMARY KEY DEFAULT lo_create(0),
name text UNIQUE NOT NULL,
size bigint,
type text,
digest text,
created_at timestamp with time zone NOT NULL DEFAULT current_timestamp
);`,
`CREATE FUNCTION delete_file() RETURNS TRIGGER AS $$
BEGIN
PERFORM lo_unlink(OLD.file_id);
RETURN NULL;
END;
$$ LANGUAGE plpgsql;`,
`CREATE TRIGGER delete_file
AFTER DELETE ON files
FOR EACH ROW EXECUTE PROCEDURE delete_file();`,
)
// TODO(jpg) reuse pkg/postgres connection when converted
connConf := pgx.ConnConfig{
Host: os.Getenv("PGHOST"),
User: os.Getenv("PGUSER"),
Password: os.Getenv("PGPASSWORD"),
Database: os.Getenv("PGDATABASE"),
}
pgxpool, err := pgx.NewConnPool(pgx.ConnPoolConfig{
ConnConfig: connConf,
})
if err != nil {
return nil, err
}
return &PostgresFilesystem{db: pgxpool}, m.Migrate(db)
}
示例3: migrateDB
func migrateDB(db *sql.DB) error {
m := postgres.NewMigrations()
m.Add(1,
`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`,
`CREATE TABLE artifacts (
artifact_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
type text NOT NULL,
uri text NOT NULL,
created_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz
)`,
`CREATE UNIQUE INDEX ON artifacts (type, uri) WHERE deleted_at IS NULL`,
`CREATE TABLE releases (
release_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
artifact_id uuid REFERENCES artifacts (artifact_id),
data jsonb NOT NULL,
created_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz
)`,
`CREATE TYPE deployment_strategy AS ENUM ('all-at-once', 'one-by-one', 'postgres')`,
`CREATE TABLE apps (
app_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
name text NOT NULL,
release_id uuid REFERENCES releases (release_id),
meta jsonb,
strategy deployment_strategy NOT NULL DEFAULT 'all-at-once',
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz
)`,
`CREATE UNIQUE INDEX ON apps (name) WHERE deleted_at IS NULL`,
`CREATE SEQUENCE event_ids`,
`CREATE TYPE event_type AS ENUM ('app_deletion', 'app', 'app_release', 'deployment', 'job', 'scale', 'release', 'artifact', 'provider', 'resource', 'resource_deletion', 'key', 'key_deletion', 'route', 'route_deletion')`,
`CREATE TABLE events (
event_id bigint PRIMARY KEY DEFAULT nextval('event_ids'),
app_id uuid REFERENCES apps (app_id),
object_type event_type NOT NULL,
object_id text NOT NULL,
unique_id text,
data jsonb,
created_at timestamptz NOT NULL DEFAULT now()
)`,
`CREATE INDEX ON events (object_type)`,
`CREATE UNIQUE INDEX ON events (unique_id)`,
`CREATE FUNCTION notify_event() RETURNS TRIGGER AS $$
BEGIN
IF NEW.app_id IS NOT NULL THEN
PERFORM pg_notify('events', NEW.event_id || ':' || NEW.app_id);
ELSE
PERFORM pg_notify('events', NEW.event_id::text);
END IF;
RETURN NULL;
END;
$$ LANGUAGE plpgsql`,
`CREATE TRIGGER notify_event
AFTER INSERT ON events
FOR EACH ROW EXECUTE PROCEDURE notify_event()`,
`CREATE TABLE formations (
app_id uuid NOT NULL REFERENCES apps (app_id),
release_id uuid NOT NULL REFERENCES releases (release_id),
processes jsonb,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz,
PRIMARY KEY (app_id, release_id)
)`,
`CREATE FUNCTION notify_formation() RETURNS TRIGGER AS $$
BEGIN
PERFORM pg_notify('formations', NEW.app_id || ':' || NEW.release_id);
RETURN NULL;
END;
$$ LANGUAGE plpgsql`,
`CREATE TRIGGER notify_formation
AFTER INSERT OR UPDATE ON formations
FOR EACH ROW EXECUTE PROCEDURE notify_formation()`,
`CREATE TABLE providers (
provider_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
name text NOT NULL UNIQUE,
url text NOT NULL UNIQUE,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz
)`,
`CREATE TABLE resources (
resource_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
provider_id uuid NOT NULL REFERENCES providers (provider_id),
external_id text NOT NULL,
env jsonb,
created_at timestamptz NOT NULL DEFAULT now(),
//.........這裏部分代碼省略.........
示例4: migrateDB
func migrateDB(db *postgres.DB) error {
m := postgres.NewMigrations()
m.Add(1,
`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`,
`CREATE FUNCTION set_updated_at_column() RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = CURRENT_TIMESTAMP AT TIME ZONE 'UTC';
RETURN NEW;
END;
$$ language 'plpgsql'`,
// tcp routes
`
CREATE TABLE tcp_routes (
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
parent_ref varchar(255) NOT NULL,
service varchar(255) NOT NULL CHECK (service <> ''),
port integer NOT NULL CHECK (port > 0 AND port < 65535),
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz
)`,
`
CREATE UNIQUE INDEX tcp_routes_port_key ON tcp_routes
USING btree (port) WHERE deleted_at IS NULL`,
`
CREATE TRIGGER set_updated_at_tcp_routes
BEFORE UPDATE ON tcp_routes FOR EACH ROW
EXECUTE PROCEDURE set_updated_at_column()`,
`
CREATE OR REPLACE FUNCTION notify_tcp_route_update() RETURNS TRIGGER AS $$
BEGIN
PERFORM pg_notify('tcp_routes', NEW.id::varchar);
RETURN NULL;
END;
$$ LANGUAGE plpgsql`,
`
CREATE TRIGGER notify_tcp_route_update
AFTER INSERT OR UPDATE OR DELETE ON tcp_routes
FOR EACH ROW EXECUTE PROCEDURE notify_tcp_route_update()`,
// http routes
`
CREATE TABLE http_routes (
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
parent_ref varchar(255) NOT NULL,
service varchar(255) NOT NULL CHECK (service <> ''),
domain varchar(255) NOT NULL CHECK (domain <> ''),
sticky bool NOT NULL DEFAULT FALSE,
tls_cert text,
tls_key text,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz
)`,
`
CREATE UNIQUE INDEX http_routes_domain_key ON http_routes
USING btree (domain) WHERE deleted_at IS NULL`,
`
CREATE TRIGGER set_updated_at_http_routes
BEFORE UPDATE ON http_routes FOR EACH ROW
EXECUTE PROCEDURE set_updated_at_column()`,
`
CREATE OR REPLACE FUNCTION notify_http_route_update() RETURNS TRIGGER AS $$
BEGIN
PERFORM pg_notify('http_routes', NEW.id::varchar);
RETURN NULL;
END;
$$ LANGUAGE plpgsql`,
`
CREATE TRIGGER notify_http_route_update
AFTER INSERT OR UPDATE OR DELETE ON http_routes
FOR EACH ROW EXECUTE PROCEDURE notify_http_route_update()`,
)
m.Add(2,
`ALTER TABLE http_routes ADD COLUMN path text NOT NULL DEFAULT '/'`,
`DROP INDEX http_routes_domain_key`,
`CREATE UNIQUE INDEX http_routes_domain_path_key ON http_routes
USING btree (domain, path) WHERE deleted_at IS NULL`,
`
CREATE OR REPLACE FUNCTION check_http_route_update() RETURNS TRIGGER AS $$
DECLARE
default_route RECORD;
dependent_routes int;
BEGIN
-- If NEW.deleted_at is NOT NULL then we are processing a delete
-- We also catch entire row deletions here but they shouldn't occur.
IF NEW IS NULL OR NEW.deleted_at IS NOT NULL THEN
-- If we are removing a default route ensure no dependent routes left
IF OLD.path = '/' THEN
SELECT count(*) INTO dependent_routes FROM http_routes
WHERE domain = OLD.domain AND path <> '/' AND deleted_at IS NULL;
IF dependent_routes > 0 THEN
RAISE EXCEPTION 'default route for % has dependent routes', OLD.domain;
END IF;
END IF;
RETURN NEW;
END IF;
//.........這裏部分代碼省略.........
示例5: init
func init() {
migrations = postgres.NewMigrations()
migrations.Add(1,
`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`,
`CREATE TABLE artifacts (
artifact_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
type text NOT NULL,
uri text NOT NULL,
created_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz
)`,
`CREATE UNIQUE INDEX ON artifacts (type, uri) WHERE deleted_at IS NULL`,
`CREATE TABLE releases (
release_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
artifact_id uuid REFERENCES artifacts (artifact_id),
meta jsonb,
env jsonb,
processes jsonb,
created_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz
)`,
`CREATE TYPE deployment_strategy AS ENUM ('all-at-once', 'one-by-one', 'postgres')`,
`CREATE TABLE apps (
app_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
name text NOT NULL,
release_id uuid REFERENCES releases (release_id),
meta jsonb,
strategy deployment_strategy NOT NULL DEFAULT 'all-at-once',
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz
)`,
`CREATE UNIQUE INDEX ON apps (name) WHERE deleted_at IS NULL`,
`CREATE SEQUENCE event_ids`,
`CREATE TYPE event_type AS ENUM ('app_deletion', 'app', 'app_release', 'deployment', 'job', 'scale', 'release', 'artifact', 'provider', 'resource', 'resource_deletion', 'key', 'key_deletion', 'route', 'route_deletion', 'domain_migration')`,
`CREATE TABLE events (
event_id bigint PRIMARY KEY DEFAULT nextval('event_ids'),
app_id uuid REFERENCES apps (app_id),
object_type event_type NOT NULL,
object_id text NOT NULL,
unique_id text,
data jsonb,
created_at timestamptz NOT NULL DEFAULT now()
)`,
`CREATE INDEX ON events (object_type)`,
`CREATE UNIQUE INDEX ON events (unique_id)`,
`CREATE FUNCTION notify_event() RETURNS TRIGGER AS $$
BEGIN
IF NEW.app_id IS NOT NULL THEN
PERFORM pg_notify('events', NEW.event_id || ':' || NEW.app_id);
ELSE
PERFORM pg_notify('events', NEW.event_id::text);
END IF;
RETURN NULL;
END;
$$ LANGUAGE plpgsql`,
`CREATE TRIGGER notify_event
AFTER INSERT ON events
FOR EACH ROW EXECUTE PROCEDURE notify_event()`,
`CREATE TABLE formations (
app_id uuid NOT NULL REFERENCES apps (app_id),
release_id uuid NOT NULL REFERENCES releases (release_id),
processes jsonb,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz,
PRIMARY KEY (app_id, release_id)
)`,
`CREATE FUNCTION notify_formation() RETURNS TRIGGER AS $$
BEGIN
PERFORM pg_notify('formations', NEW.app_id || ':' || NEW.release_id);
RETURN NULL;
END;
$$ LANGUAGE plpgsql`,
`CREATE TRIGGER notify_formation
AFTER INSERT OR UPDATE ON formations
FOR EACH ROW EXECUTE PROCEDURE notify_formation()`,
`CREATE TABLE providers (
provider_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
name text NOT NULL UNIQUE,
url text NOT NULL UNIQUE,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz
)`,
`CREATE TABLE resources (
resource_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
provider_id uuid NOT NULL REFERENCES providers (provider_id),
external_id text NOT NULL,
//.........這裏部分代碼省略.........
示例6: migrateDB
func migrateDB(db *postgres.DB) error {
m := postgres.NewMigrations()
m.Add(1,
`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`,
`CREATE FUNCTION set_updated_at_column() RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = CURRENT_TIMESTAMP AT TIME ZONE 'UTC';
RETURN NEW;
END;
$$ language 'plpgsql'`,
// tcp routes
`
CREATE TABLE tcp_routes (
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
parent_ref varchar(255) NOT NULL,
service varchar(255) NOT NULL CHECK (service <> ''),
port integer NOT NULL CHECK (port > 0 AND port < 65535),
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz
)`,
`
CREATE UNIQUE INDEX tcp_routes_port_key ON tcp_routes
USING btree (port) WHERE deleted_at IS NULL`,
`
CREATE TRIGGER set_updated_at_tcp_routes
BEFORE UPDATE ON tcp_routes FOR EACH ROW
EXECUTE PROCEDURE set_updated_at_column()`,
`
CREATE OR REPLACE FUNCTION notify_tcp_route_update() RETURNS TRIGGER AS $$
BEGIN
PERFORM pg_notify('tcp_routes', NEW.id::varchar);
RETURN NULL;
END;
$$ LANGUAGE plpgsql`,
`
CREATE TRIGGER notify_tcp_route_update
AFTER INSERT OR UPDATE OR DELETE ON tcp_routes
FOR EACH ROW EXECUTE PROCEDURE notify_tcp_route_update()`,
// http routes
`
CREATE TABLE http_routes (
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
parent_ref varchar(255) NOT NULL,
service varchar(255) NOT NULL CHECK (service <> ''),
domain varchar(255) NOT NULL CHECK (domain <> ''),
sticky bool NOT NULL DEFAULT FALSE,
tls_cert text,
tls_key text,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz
)`,
`
CREATE UNIQUE INDEX http_routes_domain_key ON http_routes
USING btree (domain) WHERE deleted_at IS NULL`,
`
CREATE TRIGGER set_updated_at_http_routes
BEFORE UPDATE ON http_routes FOR EACH ROW
EXECUTE PROCEDURE set_updated_at_column()`,
`
CREATE OR REPLACE FUNCTION notify_http_route_update() RETURNS TRIGGER AS $$
BEGIN
PERFORM pg_notify('http_routes', NEW.id::varchar);
RETURN NULL;
END;
$$ LANGUAGE plpgsql`,
`
CREATE TRIGGER notify_http_route_update
AFTER INSERT OR UPDATE OR DELETE ON http_routes
FOR EACH ROW EXECUTE PROCEDURE notify_http_route_update()`,
)
return m.Migrate(db)
}
示例7: init
log.Println("Blobstore serving files on " + addr)
mux.Handle("/", handler(repo))
mux.Handle(status.Path, status.Handler(func() status.Status {
if err := db.Exec("SELECT 1"); err != nil {
return status.Unhealthy
}
return status.Healthy
}))
h := httphelper.ContextInjector("blobstore", httphelper.NewRequestLogger(mux))
return http.ListenAndServe(addr, h)
}
var dbMigrations = postgres.NewMigrations()
func init() {
dbMigrations.Add(1,
`CREATE TABLE files (
file_id oid PRIMARY KEY DEFAULT lo_create(0),
name text UNIQUE NOT NULL,
size bigint,
type text,
digest text,
created_at timestamp with time zone NOT NULL DEFAULT current_timestamp
)`,
`CREATE FUNCTION delete_file() RETURNS TRIGGER AS $$
BEGIN
PERFORM lo_unlink(OLD.file_id);
RETURN NULL;
示例8: init
func init() {
migrations = postgres.NewMigrations()
migrations.Add(1,
`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`,
`CREATE FUNCTION set_updated_at_column() RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = CURRENT_TIMESTAMP AT TIME ZONE 'UTC';
RETURN NEW;
END;
$$ language 'plpgsql'`,
// tcp routes
`
CREATE TABLE tcp_routes (
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
parent_ref varchar(255) NOT NULL,
service varchar(255) NOT NULL CHECK (service <> ''),
port integer NOT NULL CHECK (port > 0 AND port < 65535),
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz
)`,
`
CREATE UNIQUE INDEX tcp_routes_port_key ON tcp_routes
USING btree (port) WHERE deleted_at IS NULL`,
`
CREATE TRIGGER set_updated_at_tcp_routes
BEFORE UPDATE ON tcp_routes FOR EACH ROW
EXECUTE PROCEDURE set_updated_at_column()`,
`
CREATE OR REPLACE FUNCTION notify_tcp_route_update() RETURNS TRIGGER AS $$
BEGIN
PERFORM pg_notify('tcp_routes', NEW.id::varchar);
RETURN NULL;
END;
$$ LANGUAGE plpgsql`,
`
CREATE TRIGGER notify_tcp_route_update
AFTER INSERT OR UPDATE OR DELETE ON tcp_routes
FOR EACH ROW EXECUTE PROCEDURE notify_tcp_route_update()`,
// http routes
`
CREATE TABLE http_routes (
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
parent_ref varchar(255) NOT NULL,
service varchar(255) NOT NULL CHECK (service <> ''),
domain varchar(255) NOT NULL CHECK (domain <> ''),
sticky bool NOT NULL DEFAULT FALSE,
tls_cert text,
tls_key text,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz
)`,
`
CREATE UNIQUE INDEX http_routes_domain_key ON http_routes
USING btree (domain) WHERE deleted_at IS NULL`,
`
CREATE TRIGGER set_updated_at_http_routes
BEFORE UPDATE ON http_routes FOR EACH ROW
EXECUTE PROCEDURE set_updated_at_column()`,
`
CREATE OR REPLACE FUNCTION notify_http_route_update() RETURNS TRIGGER AS $$
BEGIN
PERFORM pg_notify('http_routes', NEW.id::varchar);
RETURN NULL;
END;
$$ LANGUAGE plpgsql`,
`
CREATE TRIGGER notify_http_route_update
AFTER INSERT OR UPDATE OR DELETE ON http_routes
FOR EACH ROW EXECUTE PROCEDURE notify_http_route_update()`,
)
migrations.Add(2,
`ALTER TABLE http_routes ADD COLUMN path text NOT NULL DEFAULT '/'`,
`DROP INDEX http_routes_domain_key`,
`CREATE UNIQUE INDEX http_routes_domain_path_key ON http_routes
USING btree (domain, path) WHERE deleted_at IS NULL`,
`
CREATE OR REPLACE FUNCTION check_http_route_update() RETURNS TRIGGER AS $$
DECLARE
default_route RECORD;
dependent_routes int;
BEGIN
-- If NEW.deleted_at is NOT NULL then we are processing a delete
-- We also catch entire row deletions here but they shouldn't occur.
IF NEW IS NULL OR NEW.deleted_at IS NOT NULL THEN
-- If we are removing a default route ensure no dependent routes left
IF OLD.path = '/' THEN
SELECT count(*) INTO dependent_routes FROM http_routes
WHERE domain = OLD.domain AND path <> '/' AND deleted_at IS NULL;
IF dependent_routes > 0 THEN
RAISE EXCEPTION 'default route for % has dependent routes', OLD.domain;
END IF;
END IF;
RETURN NEW;
END IF;
//.........這裏部分代碼省略.........
示例9: init
func init() {
migrations = postgres.NewMigrations()
migrations.Add(1,
`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`,
`CREATE TABLE artifacts (
artifact_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
type text NOT NULL,
uri text NOT NULL,
created_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz
)`,
`CREATE UNIQUE INDEX ON artifacts (type, uri) WHERE deleted_at IS NULL`,
`CREATE TABLE releases (
release_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
artifact_id uuid REFERENCES artifacts (artifact_id),
meta jsonb,
env jsonb,
processes jsonb,
created_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz
)`,
`CREATE TYPE deployment_strategy AS ENUM ('all-at-once', 'one-by-one', 'postgres')`,
`CREATE TABLE apps (
app_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
name text NOT NULL,
release_id uuid REFERENCES releases (release_id),
meta jsonb,
strategy deployment_strategy NOT NULL DEFAULT 'all-at-once',
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz
)`,
`CREATE UNIQUE INDEX ON apps (name) WHERE deleted_at IS NULL`,
`CREATE SEQUENCE event_ids`,
`CREATE TYPE event_type AS ENUM ('app_deletion', 'app', 'app_release', 'deployment', 'job', 'scale', 'release', 'artifact', 'provider', 'resource', 'resource_deletion', 'key', 'key_deletion', 'route', 'route_deletion', 'domain_migration')`,
`CREATE TABLE events (
event_id bigint PRIMARY KEY DEFAULT nextval('event_ids'),
app_id uuid REFERENCES apps (app_id),
object_type event_type NOT NULL,
object_id text NOT NULL,
unique_id text,
data jsonb,
created_at timestamptz NOT NULL DEFAULT now()
)`,
`CREATE INDEX ON events (object_type)`,
`CREATE UNIQUE INDEX ON events (unique_id)`,
`CREATE FUNCTION notify_event() RETURNS TRIGGER AS $$
BEGIN
IF NEW.app_id IS NOT NULL THEN
PERFORM pg_notify('events', NEW.event_id || ':' || NEW.app_id);
ELSE
PERFORM pg_notify('events', NEW.event_id::text);
END IF;
RETURN NULL;
END;
$$ LANGUAGE plpgsql`,
`CREATE TRIGGER notify_event
AFTER INSERT ON events
FOR EACH ROW EXECUTE PROCEDURE notify_event()`,
`CREATE TABLE formations (
app_id uuid NOT NULL REFERENCES apps (app_id),
release_id uuid NOT NULL REFERENCES releases (release_id),
processes jsonb,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz,
PRIMARY KEY (app_id, release_id)
)`,
`CREATE FUNCTION notify_formation() RETURNS TRIGGER AS $$
BEGIN
PERFORM pg_notify('formations', NEW.app_id || ':' || NEW.release_id);
RETURN NULL;
END;
$$ LANGUAGE plpgsql`,
`CREATE TRIGGER notify_formation
AFTER INSERT OR UPDATE ON formations
FOR EACH ROW EXECUTE PROCEDURE notify_formation()`,
`CREATE TABLE providers (
provider_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
name text NOT NULL UNIQUE,
url text NOT NULL UNIQUE,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz
)`,
`CREATE TABLE resources (
resource_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
provider_id uuid NOT NULL REFERENCES providers (provider_id),
external_id text NOT NULL,
//.........這裏部分代碼省略.........