diff --git a/app/models/snippet.rb b/app/models/snippet.rb index 93acff57547c78d2eca094ccc5562e459d66eb79..ba30cbc71dace76b58a53960f0952b96601b7735 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -20,6 +20,9 @@ class Snippet < ApplicationRecord include CreatedAtFilterable include EachBatch include Import::HasImportSource + include SafelyChangeColumnDefault + + columns_changing_default :organization_id MAX_FILE_COUNT = 10 diff --git a/db/fixtures/development/12_snippets.rb b/db/fixtures/development/12_snippets.rb index 4f885f99846e8973c298183ce48e4e1151f93af2..caa6887a581908f7239250148a10c63b55922cc9 100644 --- a/db/fixtures/development/12_snippets.rb +++ b/db/fixtures/development/12_snippets.rb @@ -33,6 +33,7 @@ def self.cleanup title: FFaker::Lorem.sentence(3), file_name: 'file.rb', visibility_level: Gitlab::VisibilityLevel.values.sample, + organization: Organizations::Organization.default_organization, content: 'foo' }).tap do |snippet| snippet.repository.expire_exists_cache diff --git a/db/post_migrate/20240719094108_change_snippets_default.rb b/db/post_migrate/20240719094108_change_snippets_default.rb new file mode 100644 index 0000000000000000000000000000000000000000..c21dce3c3bac57502966e901a6418add4752e276 --- /dev/null +++ b/db/post_migrate/20240719094108_change_snippets_default.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class ChangeSnippetsDefault < Gitlab::Database::Migration[2.2] + DEFAULT_ORGANIZATION_ID = 1 + + milestone '17.3' + + def change + change_column_default('snippets', 'organization_id', from: DEFAULT_ORGANIZATION_ID, to: nil) + end +end diff --git a/db/schema_migrations/20240719094108 b/db/schema_migrations/20240719094108 new file mode 100644 index 0000000000000000000000000000000000000000..8cea5806381fba37c2ffd101ae45cc78109239d3 --- /dev/null +++ b/db/schema_migrations/20240719094108 @@ -0,0 +1 @@ +9d0b8d803cb0eebf25dbcba9b4013fd432fac732f91e9b2786b0ce23cf00436b \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index e69ef3f1bf00ae13f1c46068903968db5c454e88..4273b8f780408035f9d707684d55be834e0564c0 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -17748,7 +17748,7 @@ CREATE TABLE snippets ( secret boolean DEFAULT false NOT NULL, repository_read_only boolean DEFAULT false NOT NULL, imported_from smallint DEFAULT 0 NOT NULL, - organization_id bigint DEFAULT 1 + organization_id bigint ); CREATE SEQUENCE snippets_id_seq diff --git a/spec/factories/snippets.rb b/spec/factories/snippets.rb index e79387d685fa098d5ffa7bfc743cc0e8ea79bd1e..65168d040391c3fb00d7a3594edd5858e8a4ba71 100644 --- a/spec/factories/snippets.rb +++ b/spec/factories/snippets.rb @@ -51,6 +51,7 @@ factory :personal_snippet, parent: :snippet, class: :PersonalSnippet do author { association(:author, :with_namespace) } + organization { association :organization, :default } project { nil } trait :secret do