Commit 0ca479d1 authored by Tiago Botelho's avatar Tiago Botelho

adds project mirror data table

parent 27a8cc7b
class CreateProjectMirrorData < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
execute <<-SQL
CREATE TABLE project_mirror_data
AS (
SELECT id AS project_id,
0 AS retry_count,
CAST(NULL AS #{timestamp}) AS last_update_started_at,
CAST(NULL AS #{timestamp}) AS last_update_scheduled_at,
NOW() AS next_execution_timestamp,
NOW() AS created_at,
NOW() AS updated_at
FROM projects
WHERE mirror IS TRUE
);
SQL
add_column :project_mirror_data, :id, :primary_key
change_column_default :project_mirror_data, :retry_count, 0
change_column_null :project_mirror_data, :retry_count, false
add_concurrent_foreign_key :project_mirror_data, :projects, column: :project_id
add_concurrent_index :project_mirror_data, [:project_id], unique: true
end
def down
drop_table :project_mirror_data if table_exists?(:project_mirror_data)
end
def timestamp
return 'TIMESTAMP' if Gitlab::Database.postgresql?
'DATETIME'
end
end
......@@ -1079,6 +1079,18 @@ ActiveRecord::Schema.define(version: 20170602003304) do
add_index "project_import_data", ["project_id"], name: "index_project_import_data_on_project_id", using: :btree
create_table "project_mirror_data", force: :cascade do |t|
t.integer "project_id"
t.integer "retry_count", default: 0, null: false
t.datetime "last_update_started_at"
t.datetime "last_update_scheduled_at"
t.datetime "next_execution_timestamp"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "project_mirror_data", ["project_id"], name: "index_project_mirror_data_on_project_id", unique: true, using: :btree
create_table "project_statistics", force: :cascade do |t|
t.integer "project_id", null: false
t.integer "namespace_id", null: false
......@@ -1673,6 +1685,7 @@ ActiveRecord::Schema.define(version: 20170602003304) do
add_foreign_key "personal_access_tokens", "users"
add_foreign_key "project_authorizations", "projects", on_delete: :cascade
add_foreign_key "project_authorizations", "users", on_delete: :cascade
add_foreign_key "project_mirror_data", "projects", name: "fk_d1aad367d7", on_delete: :cascade
add_foreign_key "project_statistics", "projects", on_delete: :cascade
add_foreign_key "protected_branch_merge_access_levels", "namespaces", column: "group_id"
add_foreign_key "protected_branch_merge_access_levels", "protected_branches"
......
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