Skip to content
Snippets Groups Projects
Unverified Commit 6719128b authored by João Pereira's avatar João Pereira
Browse files

Add migrations

parent cf1dad2c
No related merge requests found
package migrations
import migrate "github.com/rubenv/sql-migrate"
func init() {
m := &migrate.Migration{
Id: "20200319122755_create_repositories_table",
Up: []string{
`CREATE TABLE IF NOT EXISTS repositories (
id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
parent_id bigint,
created_at timestamp WITH time zone NOT NULL DEFAULT now(),
updated_at timestamp WITH time zone,
name text NOT NULL,
path text NOT NULL,
CONSTRAINT pk_repositories PRIMARY KEY (id),
CONSTRAINT fk_repositories_parent_id_repositories FOREIGN KEY (parent_id) REFERENCES repositories (id) ON DELETE CASCADE,
CONSTRAINT uq_repositories_path UNIQUE (path),
CONSTRAINT ck_repositories_name_length CHECK ((char_length(name) <= 255)),
CONSTRAINT ck_repositories_path_length CHECK ((char_length(path) <= 255))
)`,
"CREATE INDEX IF NOT EXISTS ix_repositories_parent_id ON repositories (parent_id)",
},
Down: []string{
"DROP INDEX IF EXISTS ix_repositories_parent_id CASCADE",
"DROP TABLE IF EXISTS repositories CASCADE",
},
}
allMigrations = append(allMigrations, m)
}
package migrations
import migrate "github.com/rubenv/sql-migrate"
func init() {
m := &migrate.Migration{
Id: "20200319130108_create_blobs_table",
Up: []string{
`CREATE TABLE IF NOT EXISTS blobs (
id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
size bigint NOT NULL,
created_at timestamp WITH time zone NOT NULL DEFAULT now(),
marked_at timestamp WITH time zone,
digest_algorithm smallint NOT NULL,
digest_hex bytea NOT NULL,
media_type text NOT NULL,
CONSTRAINT pk_blobs PRIMARY KEY (id),
CONSTRAINT uq_blobs_digest_algorithm_digest_hex UNIQUE (digest_algorithm, digest_hex),
CONSTRAINT ck_blobs_digest_algorithm_enum CHECK ((digest_algorithm IN (1, 2))),
CONSTRAINT ck_blobs_media_type_length CHECK ((char_length(media_type) <= 255))
)`,
},
Down: []string{
"DROP TABLE IF EXISTS blobs CASCADE",
},
}
allMigrations = append(allMigrations, m)
}
package migrations
import migrate "github.com/rubenv/sql-migrate"
func init() {
m := &migrate.Migration{
Id: "20200319131542_create_configurations_table",
Up: []string{
`CREATE TABLE IF NOT EXISTS configurations (
id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
blob_id bigint NOT NULL,
created_at timestamp WITH time zone NOT NULL DEFAULT now(),
payload bytea NOT NULL,
CONSTRAINT pk_configurations PRIMARY KEY (id),
CONSTRAINT fk_configurations_blob_id_blobs FOREIGN KEY (blob_id) REFERENCES blobs (id) ON DELETE CASCADE,
CONSTRAINT uq_configurations_blob_id UNIQUE (blob_id)
)`,
"CREATE INDEX IF NOT EXISTS ix_configurations_blob_id ON configurations (blob_id)",
},
Down: []string{
"DROP INDEX IF EXISTS ix_configurations_blob_id CASCADE",
"DROP TABLE IF EXISTS configurations CASCADE",
},
}
allMigrations = append(allMigrations, m)
}
package migrations
import migrate "github.com/rubenv/sql-migrate"
func init() {
m := &migrate.Migration{
Id: "20200319131542_create_manifests_table",
Up: []string{
`CREATE TABLE IF NOT EXISTS manifests (
id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
configuration_id bigint,
created_at timestamp WITH time zone NOT NULL DEFAULT now(),
marked_at timestamp WITH time zone,
schema_version integer NOT NULL,
digest_algorithm smallint NOT NULL,
digest_hex bytea NOT NULL,
payload bytea NOT NULL,
media_type text NOT NULL,
CONSTRAINT pk_manifests PRIMARY KEY (id),
CONSTRAINT fk_manifests_configuration_id_configurations FOREIGN KEY (configuration_id) REFERENCES configurations (id) ON DELETE CASCADE,
CONSTRAINT uq_manifests_digest_algorithm_digest_hex UNIQUE (digest_algorithm, digest_hex),
CONSTRAINT ck_manifests_digest_algorithm_enum CHECK ((digest_algorithm IN (1, 2))),
CONSTRAINT ck_manifests_media_type_length CHECK ((char_length(media_type) <= 255))
)`,
"CREATE INDEX IF NOT EXISTS ix_manifests_configuration_id ON manifests (configuration_id) WHERE configuration_id IS NOT NULL",
},
Down: []string{
"DROP INDEX IF EXISTS ix_manifests_configuration_id CASCADE",
"DROP TABLE IF EXISTS manifests CASCADE",
},
}
allMigrations = append(allMigrations, m)
}
package migrations
import migrate "github.com/rubenv/sql-migrate"
func init() {
m := &migrate.Migration{
Id: "20200319131632_create_manifest_layers_table",
Up: []string{
`CREATE TABLE IF NOT EXISTS manifest_layers (
id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
manifest_id bigint NOT NULL,
blob_id bigint NOT NULL,
created_at timestamp WITH time zone NOT NULL DEFAULT now(),
CONSTRAINT pk_manifest_layers PRIMARY KEY (id),
CONSTRAINT fk_manifest_layers_manifest_id_manifests FOREIGN KEY (manifest_id) REFERENCES manifests (id) ON DELETE CASCADE,
CONSTRAINT fk_manifest_layers_blob_id_blobs FOREIGN KEY (blob_id) REFERENCES blobs (id) ON DELETE CASCADE,
CONSTRAINT uq_manifest_layers_manifest_id_blob_id UNIQUE (manifest_id, blob_id)
)`,
"CREATE INDEX IF NOT EXISTS ix_manifest_layers_manifest_id ON manifest_layers (manifest_id)",
"CREATE INDEX IF NOT EXISTS ix_manifest_layers_blob_id ON manifest_layers (blob_id)",
},
Down: []string{
"DROP INDEX IF EXISTS ix_manifest_layers_blob_id CASCADE",
"DROP INDEX IF EXISTS ix_manifest_layers_manifest_id CASCADE",
"DROP TABLE IF EXISTS manifest_layers CASCADE",
},
}
allMigrations = append(allMigrations, m)
}
package migrations
import migrate "github.com/rubenv/sql-migrate"
func init() {
m := &migrate.Migration{
Id: "20200319132010_create_manifest_references_table",
Up: []string{
`CREATE TABLE IF NOT EXISTS manifest_references (
id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
parent_id bigint NOT NULL,
child_id bigint NOT NULL,
created_at timestamp WITH time zone NOT NULL DEFAULT now(),
CONSTRAINT pk_manifest_references PRIMARY KEY (id),
CONSTRAINT fk_manifest_references_parent_id_manifests FOREIGN KEY (parent_id) REFERENCES manifests (id) ON DELETE CASCADE,
CONSTRAINT fk_manifest_references_child_id_manifests FOREIGN KEY (child_id) REFERENCES manifests (id) ON DELETE CASCADE,
CONSTRAINT uq_manifest_references_parent_id_child_id UNIQUE (parent_id, child_id),
CONSTRAINT ck_manifest_references_parent_id_child_id_differ CHECK ((parent_id <> child_id))
)`,
"CREATE INDEX IF NOT EXISTS ix_manifest_references_parent_id ON manifest_references (parent_id)",
"CREATE INDEX IF NOT EXISTS ix_manifest_references_child_id ON manifest_references (child_id)",
},
Down: []string{
"DROP INDEX IF EXISTS ix_manifest_references_child_id CASCADE",
"DROP INDEX IF EXISTS ix_manifest_references_parent_id CASCADE",
"DROP TABLE IF EXISTS manifest_references CASCADE",
},
}
allMigrations = append(allMigrations, m)
}
package migrations
import migrate "github.com/rubenv/sql-migrate"
func init() {
m := &migrate.Migration{
Id: "20200319132237_create_tags_table",
Up: []string{
`CREATE TABLE IF NOT EXISTS tags (
id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
repository_id bigint NOT NULL,
manifest_id bigint NOT NULL,
created_at timestamp WITH time zone NOT NULL DEFAULT now(),
updated_at timestamp WITH time zone,
name text NOT NULL,
CONSTRAINT pk_tags PRIMARY KEY (id),
CONSTRAINT fk_tags_repository_id_repositories FOREIGN KEY (repository_id) REFERENCES repositories (id) ON DELETE CASCADE,
CONSTRAINT fk_tags_manifest_id_manifests FOREIGN KEY (manifest_id) REFERENCES manifests (id) ON DELETE CASCADE,
CONSTRAINT uq_tags_name_repository_id UNIQUE (name, repository_id),
CONSTRAINT ck_tags_name_length CHECK ((char_length(name) <= 255))
)`,
"CREATE INDEX IF NOT EXISTS ix_tags_repository_id ON tags (repository_id)",
"CREATE INDEX IF NOT EXISTS ix_tags_manifest_id ON tags (manifest_id)",
},
Down: []string{
"DROP INDEX IF EXISTS ix_tags_manifest_id CASCADE",
"DROP INDEX IF EXISTS ix_tags_repository_id CASCADE",
"DROP TABLE IF EXISTS tags CASCADE",
},
}
allMigrations = append(allMigrations, m)
}
package migrations
import migrate "github.com/rubenv/sql-migrate"
func init() {
m := &migrate.Migration{
Id: "20200408192311_create_repository_manifests_table",
Up: []string{
`CREATE TABLE IF NOT EXISTS repository_manifests (
id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
repository_id bigint NOT NULL,
manifest_id bigint NOT NULL,
created_at timestamp WITH time zone NOT NULL DEFAULT now(),
CONSTRAINT pk_repository_manifests PRIMARY KEY (id),
CONSTRAINT fk_repository_manifests_repository_id_repositories FOREIGN KEY (repository_id) REFERENCES repositories (id) ON DELETE CASCADE,
CONSTRAINT fk_repository_manifests_manifest_id_manifests FOREIGN KEY (manifest_id) REFERENCES manifests (id) ON DELETE CASCADE,
CONSTRAINT uq_repository_manifests_repository_id_manifest_id UNIQUE (repository_id, manifest_id)
)`,
"CREATE INDEX IF NOT EXISTS ix_repository_manifests_repository_id ON repository_manifests (repository_id)",
"CREATE INDEX IF NOT EXISTS ix_repository_manifests_manifest_id ON repository_manifests (manifest_id)",
},
Down: []string{
"DROP INDEX IF EXISTS ix_repository_manifests_manifest_id CASCADE",
"DROP INDEX IF EXISTS ix_repository_manifests_repository_id CASCADE",
"DROP TABLE IF EXISTS repository_manifests CASCADE",
},
}
allMigrations = append(allMigrations, m)
}
package migrations
import migrate "github.com/rubenv/sql-migrate"
func init() {
m := &migrate.Migration{
Id: "20200527132906_create_repository_blobs_table",
Up: []string{
`CREATE TABLE IF NOT EXISTS repository_blobs (
id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
repository_id bigint NOT NULL,
blob_id bigint NOT NULL,
created_at timestamp WITH time zone NOT NULL DEFAULT now(),
CONSTRAINT pk_repository_blobs PRIMARY KEY (id),
CONSTRAINT fk_repository_blobs_repository_id_repositories FOREIGN KEY (repository_id) REFERENCES repositories (id) ON DELETE CASCADE,
CONSTRAINT fk_repository_blobs_blob_id_blobs FOREIGN KEY (blob_id) REFERENCES blobs (id) ON DELETE CASCADE,
CONSTRAINT uq_repository_blobs_repository_id_blob_id UNIQUE (repository_id, blob_id)
)`,
"CREATE INDEX IF NOT EXISTS ix_repository_blobs_repository_id ON repository_blobs (repository_id)",
"CREATE INDEX IF NOT EXISTS ix_repository_blobs_blob_id ON repository_blobs (blob_id)",
},
Down: []string{
"DROP INDEX IF EXISTS ix_repository_blobs_blob_id CASCADE",
"DROP INDEX IF EXISTS ix_repository_blobs_repository_id CASCADE",
"DROP TABLE IF EXISTS repository_blobs CASCADE",
},
}
allMigrations = append(allMigrations, m)
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment