registry/datastore/migrations/premigrations/20210503152325_create_layers_table.go (39 lines of code) (raw):

package premigrations import ( "github.com/docker/distribution/registry/datastore/migrations" migrate "github.com/rubenv/sql-migrate" ) func init() { m := &migrations.Migration{ Migration: &migrate.Migration{ Id: "20210503152325_create_layers_table", Up: []string{ `CREATE TABLE IF NOT EXISTS layers ( id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, top_level_namespace_id bigint NOT NULL, repository_id bigint NOT NULL, manifest_id bigint NOT NULL, size bigint NOT NULL, created_at timestamp WITH time zone NOT NULL DEFAULT now(), media_type_id smallint NOT NULL, digest bytea NOT NULL, CONSTRAINT pk_layers PRIMARY KEY (top_level_namespace_id, repository_id, id), CONSTRAINT fk_layers_top_lvl_nmspc_id_and_repo_id_and_manifst_id_manifests FOREIGN KEY (top_level_namespace_id, repository_id, manifest_id) REFERENCES manifests (top_level_namespace_id, repository_id, id) ON DELETE CASCADE, CONSTRAINT fk_layers_media_type_id_media_types FOREIGN KEY (media_type_id) REFERENCES media_types (id), CONSTRAINT fk_layers_digest_blobs FOREIGN KEY (digest) REFERENCES blobs (digest), CONSTRAINT unique_layers_tp_lvl_nmspc_id_rpstry_id_and_mnfst_id_and_digest UNIQUE (top_level_namespace_id, repository_id, manifest_id, digest), CONSTRAINT unique_layers_top_lvl_nmspc_id_and_rpstory_id_and_id_and_digest UNIQUE (top_level_namespace_id, repository_id, id, digest) ) PARTITION BY HASH (top_level_namespace_id)`, "CREATE INDEX IF NOT EXISTS index_layers_on_media_type_id ON layers USING btree (media_type_id)", "CREATE INDEX IF NOT EXISTS index_layers_on_digest ON layers (digest)", }, Down: []string{ "DROP INDEX IF EXISTS index_layers_on_digest CASCADE", "DROP INDEX IF EXISTS index_layers_on_media_type_id CASCADE", "DROP TABLE IF EXISTS layers CASCADE", }, }, } migrations.AppendPreMigration(m) }