From 20727db1702849b78e6714197f16f602f68cecf8 Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Thu, 28 Sep 2017 15:34:09 +0200 Subject: [PATCH] Add a model for `fork_networks` The fork network will keep track of the root project as long as it's present. --- app/models/fork_network.rb | 3 ++ .../20170928124105_create_fork_networks.rb | 28 +++++++++++++++++++ db/schema.rb | 8 ++++++ spec/lib/gitlab/import_export/all_models.yml | 3 ++ spec/models/fork_network_spec.rb | 5 ++++ 5 files changed, 47 insertions(+) create mode 100644 app/models/fork_network.rb create mode 100644 db/migrate/20170928124105_create_fork_networks.rb create mode 100644 spec/models/fork_network_spec.rb diff --git a/app/models/fork_network.rb b/app/models/fork_network.rb new file mode 100644 index 00000000000..60c8c167b21 --- /dev/null +++ b/app/models/fork_network.rb @@ -0,0 +1,3 @@ +class ForkNetwork < ActiveRecord::Base + belongs_to :root_project +end diff --git a/db/migrate/20170928124105_create_fork_networks.rb b/db/migrate/20170928124105_create_fork_networks.rb new file mode 100644 index 00000000000..ca906b953a3 --- /dev/null +++ b/db/migrate/20170928124105_create_fork_networks.rb @@ -0,0 +1,28 @@ +class CreateForkNetworks < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + create_table :fork_networks do |t| + t.references :root_project, + references: :projects, + index: { unique: true } + + t.string :deleted_root_project_name + end + + add_concurrent_foreign_key :fork_networks, :projects, + column: :root_project_id, + on_delete: :nullify + end + + def down + if foreign_keys_for(:fork_networks, :root_project_id).any? + remove_foreign_key :fork_networks, column: :root_project_id + end + drop_table :fork_networks + end +end diff --git a/db/schema.rb b/db/schema.rb index 25aa15b837f..d7e1a2c94fa 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -591,6 +591,13 @@ ActiveRecord::Schema.define(version: 20171006091000) do add_index "features", ["key"], name: "index_features_on_key", unique: true, using: :btree + create_table "fork_networks", force: :cascade do |t| + t.integer "root_project_id" + t.string "deleted_root_project_name" + end + + add_index "fork_networks", ["root_project_id"], name: "index_fork_networks_on_root_project_id", unique: true, using: :btree + create_table "forked_project_links", force: :cascade do |t| t.integer "forked_to_project_id", null: false t.integer "forked_from_project_id", null: false @@ -1793,6 +1800,7 @@ ActiveRecord::Schema.define(version: 20171006091000) do add_foreign_key "environments", "projects", name: "fk_d1c8c1da6a", on_delete: :cascade add_foreign_key "events", "projects", on_delete: :cascade add_foreign_key "events", "users", column: "author_id", name: "fk_edfd187b6f", on_delete: :cascade + add_foreign_key "fork_networks", "projects", column: "root_project_id", name: "fk_e7b436b2b5", on_delete: :nullify add_foreign_key "forked_project_links", "projects", column: "forked_to_project_id", name: "fk_434510edb0", on_delete: :cascade add_foreign_key "gcp_clusters", "projects", on_delete: :cascade add_foreign_key "gcp_clusters", "services", on_delete: :nullify diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index c457bda9dcb..29baa70d5ae 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -272,6 +272,9 @@ project: - uploads - members_and_requesters - build_trace_section_names +- root_of_fork_network +- fork_network_member +- fork_network award_emoji: - awardable - user diff --git a/spec/models/fork_network_spec.rb b/spec/models/fork_network_spec.rb new file mode 100644 index 00000000000..b7758a0fbb5 --- /dev/null +++ b/spec/models/fork_network_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ForkNetwork, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end