Commit c7a93522 authored by Tiger Watson's avatar Tiger Watson

Merge branch 'alexives/237924/tables_for_versioned_tf_state' into 'master'

Database changes to support tf state version replicaiton

Closes #237924

See merge request gitlab-org/gitlab!42492
parents 2013755c 605483a8
---
title: Database changes to support terraform state version replicaiton
merge_request: 42492
author:
type: added
# frozen_string_literal: true
class AddVerificationStateToTerraformStateVersion < ActiveRecord::Migration[6.0]
DOWNTIME = false
def change
change_table(:terraform_state_versions) do |t|
t.integer :verification_retry_count, limit: 2
t.column :verification_retry_at, :datetime_with_timezone
t.column :verified_at, :datetime_with_timezone
t.binary :verification_checksum, using: 'verification_checksum::bytea'
# rubocop:disable Migration/AddLimitToTextColumns
t.text :verification_failure
# rubocop:enable Migration/AddLimitToTextColumns
end
end
end
# frozen_string_literal: true
class AddVerificationFailureLimitToTerraformStateVersion < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
CONSTRAINT_NAME = 'tf_state_versions_verification_failure_text_limit'
def up
add_text_limit :terraform_state_versions, :verification_failure, 255, constraint_name: CONSTRAINT_NAME
end
def down
remove_check_constraint(:terraform_state_versions, CONSTRAINT_NAME)
end
end
# frozen_string_literal: true
class AddVerificationFailureIndexToTerraformStateVersion < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
FAILURE_INDEX_NAME = 'terraform_state_versions_verification_failure_partial'
CHECKSUM_INDEX_NAME = 'terraform_state_versions_verification_checksum_partial'
disable_ddl_transaction!
def up
add_concurrent_index :terraform_state_versions, :verification_failure,
where: "(verification_failure IS NOT NULL)",
name: FAILURE_INDEX_NAME
add_concurrent_index :terraform_state_versions, :verification_checksum,
where: "(verification_checksum IS NOT NULL)",
name: CHECKSUM_INDEX_NAME
end
def down
remove_concurrent_index_by_name :terraform_state_versions, FAILURE_INDEX_NAME
remove_concurrent_index_by_name :terraform_state_versions, CHECKSUM_INDEX_NAME
end
end
b2d8b7aef4e6756f54f2a173280d98e8fc5594075aaa0a46c81b549a96730668
\ No newline at end of file
46e86bee146e7f9cf9459309f8d386f9616ba59d40a7517e22756a6e51526056
\ No newline at end of file
8b6caa84be77679e8b47dd5f20093e7438d70641d6d5fc498b05b5c35ef3e5e8
\ No newline at end of file
...@@ -16075,7 +16075,13 @@ CREATE TABLE public.terraform_state_versions ( ...@@ -16075,7 +16075,13 @@ CREATE TABLE public.terraform_state_versions (
version integer NOT NULL, version integer NOT NULL,
file_store smallint NOT NULL, file_store smallint NOT NULL,
file text NOT NULL, file text NOT NULL,
CONSTRAINT check_0824bb7bbd CHECK ((char_length(file) <= 255)) verification_retry_count smallint,
verification_retry_at timestamp with time zone,
verified_at timestamp with time zone,
verification_checksum bytea,
verification_failure text,
CONSTRAINT check_0824bb7bbd CHECK ((char_length(file) <= 255)),
CONSTRAINT tf_state_versions_verification_failure_text_limit CHECK ((char_length(verification_failure) <= 255))
); );
CREATE SEQUENCE public.terraform_state_versions_id_seq CREATE SEQUENCE public.terraform_state_versions_id_seq
...@@ -21552,6 +21558,10 @@ CREATE UNIQUE INDEX taggings_idx ON public.taggings USING btree (tag_id, taggabl ...@@ -21552,6 +21558,10 @@ CREATE UNIQUE INDEX taggings_idx ON public.taggings USING btree (tag_id, taggabl
CREATE UNIQUE INDEX term_agreements_unique_index ON public.term_agreements USING btree (user_id, term_id); CREATE UNIQUE INDEX term_agreements_unique_index ON public.term_agreements USING btree (user_id, term_id);
CREATE INDEX terraform_state_versions_verification_checksum_partial ON public.terraform_state_versions USING btree (verification_checksum) WHERE (verification_checksum IS NOT NULL);
CREATE INDEX terraform_state_versions_verification_failure_partial ON public.terraform_state_versions USING btree (verification_failure) WHERE (verification_failure IS NOT NULL);
CREATE INDEX terraform_states_verification_checksum_partial ON public.terraform_states USING btree (verification_checksum) WHERE (verification_checksum IS NOT NULL); CREATE INDEX terraform_states_verification_checksum_partial ON public.terraform_states USING btree (verification_checksum) WHERE (verification_checksum IS NOT NULL);
CREATE INDEX terraform_states_verification_failure_partial ON public.terraform_states USING btree (verification_failure) WHERE (verification_failure IS NOT NULL); CREATE INDEX terraform_states_verification_failure_partial ON public.terraform_states USING btree (verification_failure) WHERE (verification_failure IS NOT NULL);
......
# frozen_string_literal: true
class CreateTerraformStateVersionRegistry < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
unless table_exists?(:terraform_state_version_registry)
ActiveRecord::Base.transaction do
create_table :terraform_state_version_registry, id: :bigserial, force: :cascade do |t|
t.bigint :terraform_state_version_id, null: false
t.integer :state, default: 0, null: false, limit: 2
t.integer :retry_count, default: 0, null: false, limit: 2
t.datetime_with_timezone :retry_at
t.datetime_with_timezone :last_synced_at
t.datetime_with_timezone :created_at, null: false
t.text :last_sync_failure
t.index :terraform_state_version_id, name: :index_tf_state_versions_registry_on_tf_state_versions_id
t.index :retry_at
t.index :state
end
end
end
add_text_limit :terraform_state_version_registry, :last_sync_failure, 255
end
def down
drop_table :terraform_state_version_registry
end
end
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_08_27_120552) do ActiveRecord::Schema.define(version: 2020_09_15_152620) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
...@@ -209,4 +209,17 @@ ActiveRecord::Schema.define(version: 2020_08_27_120552) do ...@@ -209,4 +209,17 @@ ActiveRecord::Schema.define(version: 2020_08_27_120552) do
t.index ["terraform_state_id"], name: "index_terraform_state_registry_on_terraform_state_id" t.index ["terraform_state_id"], name: "index_terraform_state_registry_on_terraform_state_id"
end end
create_table "terraform_state_version_registry", force: :cascade do |t|
t.bigint "terraform_state_version_id", null: false
t.integer "state", limit: 2, default: 0, null: false
t.integer "retry_count", limit: 2, default: 0, null: false
t.datetime_with_timezone "retry_at"
t.datetime_with_timezone "last_synced_at"
t.datetime_with_timezone "created_at", null: false
t.text "last_sync_failure"
t.index ["retry_at"], name: "index_terraform_state_version_registry_on_retry_at"
t.index ["state"], name: "index_terraform_state_version_registry_on_state"
t.index ["terraform_state_version_id"], name: "index_tf_state_versions_registry_on_tf_state_versions_id"
end
end end
Markdown is supported
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