Add a model for fork_networks

The fork network will keep track of the root project as long as it's
present.
This commit is contained in:
Bob Van Landuyt 2017-09-28 15:34:09 +02:00
parent 8eec69ef41
commit 20727db170
5 changed files with 47 additions and 0 deletions

View file

@ -0,0 +1,3 @@
class ForkNetwork < ActiveRecord::Base
belongs_to :root_project
end

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe ForkNetwork, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end