Commit d5b18344 authored by Suleimi Ahmed's avatar Suleimi Ahmed 🔴 Committed by Hayley Swimelar
Browse files

feat(datastore): create bbm tables

parent 5de4f995
Loading
Loading
Loading
Loading
+32 −0
Changes for registry/datastore/migrations/20240604074823_create_batched_background_migrations_table.go: 32 added lines, 0 removed lines.
Original line number Diff line number Diff line
package migrations

import migrate "github.com/rubenv/sql-migrate"

func init() {
	m := &Migration{
		Migration: &migrate.Migration{
			Id: "20240604074823_create_batched_background_migrations_table",
			Up: []string{
				`CREATE TABLE batched_background_migrations (
					id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
					name text NOT NULL,
					created_at timestamp WITH time zone NOT NULL DEFAULT now(),
					updated_at timestamp WITH time zone,
					min_value bigint DEFAULT 1 NOT NULL,
					max_value bigint NOT NULL,
					batch_size integer NOT NULL,
					status smallint DEFAULT 0 NOT NULL,
					job_signature_name text NOT NULL,
					table_name text NOT NULL,
					column_name text NOT NULL,
					CONSTRAINT pk_batched_background_migrations PRIMARY KEY (id),
					CONSTRAINT unique_batched_background_migrations_name UNIQUE (name)
				)`,
			},
			Down: []string{"DROP TABLE IF EXISTS batched_background_migrations CASCADE"},
		},
		PostDeployment: false,
	}

	allMigrations = append(allMigrations, m)
}
+31 −0
Changes for registry/datastore/migrations/20240604074846_create_batched_background_migration_jobs_table.go: 31 added lines, 0 removed lines.
Original line number Diff line number Diff line
package migrations

import migrate "github.com/rubenv/sql-migrate"

func init() {
	m := &Migration{
		Migration: &migrate.Migration{
			Id: "20240604074846_create_batched_background_migration_jobs_table",
			Up: []string{
				`CREATE TABLE batched_background_migration_jobs (
					id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
					created_at timestamp WITH time zone NOT NULL DEFAULT now(),
					updated_at timestamp WITH time zone,
					started_at timestamp WITH time zone,
					finished_at timestamp WITH time zone,
					batched_background_migration_id bigint NOT NULL,
					min_value bigint NOT NULL,
					max_value bigint NOT NULL,
					status smallint DEFAULT 1 NOT NULL,
					failure_error_code smallint,
					attempts smallint DEFAULT 0 NOT NULL,
					CONSTRAINT pk_batched_background_migrations_job PRIMARY KEY (id),
					CONSTRAINT fk_batched_background_migration_jobs_bbm_id_bbms FOREIGN KEY (batched_background_migration_id) REFERENCES batched_background_migrations (id) ON DELETE CASCADE
				)`},
			Down: []string{"DROP TABLE IF EXISTS batched_background_migration_jobs CASCADE"},
		},
		PostDeployment: false,
	}

	allMigrations = append(allMigrations, m)
}
+56 −0
Changes for registry/datastore/migrations/structure.sql: 56 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -5533,6 +5533,50 @@ CREATE TABLE partitions.tags_p_9 (
    CONSTRAINT check_tags_name_length CHECK ((char_length(name) <= 255))
);
CREATE TABLE public.batched_background_migration_jobs (
    id bigint NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone,
    started_at timestamp with time zone,
    finished_at timestamp with time zone,
    batched_background_migration_id bigint NOT NULL,
    min_value bigint NOT NULL,
    max_value bigint NOT NULL,
    status smallint DEFAULT 1 NOT NULL,
    failure_error_code smallint,
    attempts smallint DEFAULT 0 NOT NULL
);
ALTER TABLE public.batched_background_migration_jobs
    ALTER COLUMN id
    ADD GENERATED BY DEFAULT AS IDENTITY (SEQUENCE NAME
        public.batched_background_migration_jobs_id_seq START WITH 1 INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1);
CREATE TABLE public.batched_background_migrations (
    id bigint NOT NULL,
    name text NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone,
    min_value bigint DEFAULT 1 NOT NULL,
    max_value bigint NOT NULL,
    batch_size integer NOT NULL,
    status smallint DEFAULT 0 NOT NULL,
    job_signature_name text NOT NULL,
    table_name text NOT NULL,
    column_name text NOT NULL
);
ALTER TABLE public.batched_background_migrations
    ALTER COLUMN id
    ADD GENERATED BY DEFAULT AS IDENTITY (SEQUENCE NAME
        public.batched_background_migrations_id_seq START WITH 1 INCREMENT BY 1
        NO MINVALUE
        NO MAXVALUE
        CACHE 1);
CREATE TABLE public.gc_blob_review_queue (
    review_after timestamp with time zone DEFAULT (now() + '1 day'::interval) NOT NULL,
    review_count integer DEFAULT 0 NOT NULL,
@@ -10536,6 +10580,12 @@ ALTER TABLE ONLY partitions.tags_p_9
ALTER TABLE ONLY partitions.tags_p_9
    ADD CONSTRAINT tags_p_9_top_level_namespace_id_repository_id_name_key UNIQUE (top_level_namespace_id, repository_id, name);
ALTER TABLE ONLY public.batched_background_migrations
    ADD CONSTRAINT pk_batched_background_migrations PRIMARY KEY (id);
ALTER TABLE ONLY public.batched_background_migration_jobs
    ADD CONSTRAINT pk_batched_background_migrations_job PRIMARY KEY (id);
ALTER TABLE ONLY public.gc_blob_review_queue
    ADD CONSTRAINT pk_gc_blob_review_queue PRIMARY KEY (digest);
@@ -10560,6 +10610,9 @@ ALTER TABLE ONLY public.top_level_namespaces
ALTER TABLE ONLY public.schema_migrations
    ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.batched_background_migrations
    ADD CONSTRAINT unique_batched_background_migrations_name UNIQUE (name);
ALTER TABLE ONLY public.media_types
    ADD CONSTRAINT unique_media_types_type UNIQUE (media_type);
@@ -16160,6 +16213,9 @@ CREATE TRIGGER gc_track_tmp_blobs_manifests_trigger
    FOR EACH ROW
    EXECUTE FUNCTION public.gc_track_tmp_blobs_manifests ();
ALTER TABLE ONLY public.batched_background_migration_jobs
    ADD CONSTRAINT fk_batched_background_migration_jobs_bbm_id_bbms FOREIGN KEY (batched_background_migration_id) REFERENCES public.batched_background_migrations (id) ON DELETE CASCADE;
ALTER TABLE public.blobs
    ADD CONSTRAINT fk_blobs_media_type_id_media_types FOREIGN KEY (media_type_id) REFERENCES public.media_types (id);