Commit b21156d5 authored by Aakriti Gupta's avatar Aakriti Gupta

Add 3 tables for code analytics feature

The 3 tables relate commits, files edited and
a count of total edits made on those files.
The relevant indices are added.
parent 8fd5bf8f
# frozen_string_literal: true
class CreateAnalyticsRepositoryFilesTable < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change
create_table :analytics_repository_files do |t|
t.references :project,
index: false,
foreign_key: { on_delete: :cascade },
null: false
t.string :file_path,
limit: 4096,
null: false
end
add_index :analytics_repository_files, [:project_id, :file_path], unique: true
end
end
# frozen_string_literal: true
class CreateAnalyticsRepositoryCommitsTable < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change
create_table :analytics_repository_commits do |t|
t.references :project,
index: false,
foreign_key: { on_delete: :cascade },
null: false
t.binary :commit_sha,
null: false
t.datetime_with_timezone :committed_at,
null: false
end
add_index :analytics_repository_commits, [:project_id, :commit_sha], unique: true
end
end
# frozen_string_literal: true
class CreateAnalyticsRepositoryFileEditsTable < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change
create_table :analytics_repository_file_edits do |t|
t.references :project,
index: true,
foreign_key: { on_delete: :cascade }, null: false
t.references :analytics_repository_file,
index: false,
foreign_key: { on_delete: :cascade },
null: false
t.references :analytics_repository_commit,
index: { name: 'index_analytics_repository_file_edits_on_commit_id' },
foreign_key: { on_delete: :cascade },
null: false
t.integer :num_edits,
null: false,
default: 0
end
add_index :analytics_repository_file_edits,
[:analytics_repository_file_id, :analytics_repository_commit_id, :project_id],
name: 'index_analytics_file_edits_on_commit_id_file_id_and_project_id',
unique: true
end
end
......@@ -93,6 +93,29 @@ ActiveRecord::Schema.define(version: 2019_09_14_223900) do
t.index ["project_id"], name: "analytics_repository_languages_on_project_id"
end
create_table "analytics_repository_commits", force: :cascade do |t|
t.bigint "project_id", null: false
t.binary "commit_sha", null: false
t.datetime_with_timezone "committed_at", null: false
t.index ["project_id", "commit_sha"], name: "index_analytics_repository_commits_on_project_id_and_commit_sha", unique: true
end
create_table "analytics_repository_file_edits", force: :cascade do |t|
t.bigint "project_id", null: false
t.bigint "analytics_repository_file_id", null: false
t.bigint "analytics_repository_commit_id", null: false
t.integer "num_edits", default: 0, null: false
t.index ["analytics_repository_commit_id"], name: "index_analytics_repository_file_edits_on_commit_id"
t.index ["analytics_repository_file_id", "analytics_repository_commit_id", "project_id"], name: "index_analytics_file_edits_on_commit_id_file_id_and_project_id", unique: true
t.index ["project_id"], name: "index_analytics_repository_file_edits_on_project_id"
end
create_table "analytics_repository_files", force: :cascade do |t|
t.bigint "project_id", null: false
t.string "file_path", limit: 4096, null: false
t.index ["project_id", "file_path"], name: "index_analytics_repository_files_on_project_id_and_file_path", unique: true
end
create_table "appearances", id: :serial, force: :cascade do |t|
t.string "title", null: false
t.text "description", null: false
......@@ -3788,6 +3811,11 @@ ActiveRecord::Schema.define(version: 2019_09_14_223900) do
add_foreign_key "analytics_cycle_analytics_project_stages", "projects", on_delete: :cascade
add_foreign_key "analytics_language_trend_repository_languages", "programming_languages", on_delete: :cascade
add_foreign_key "analytics_language_trend_repository_languages", "projects", on_delete: :cascade
add_foreign_key "analytics_repository_commits", "projects", on_delete: :cascade
add_foreign_key "analytics_repository_file_edits", "analytics_repository_commits", on_delete: :cascade
add_foreign_key "analytics_repository_file_edits", "analytics_repository_files", on_delete: :cascade
add_foreign_key "analytics_repository_file_edits", "projects", on_delete: :cascade
add_foreign_key "analytics_repository_files", "projects", on_delete: :cascade
add_foreign_key "application_settings", "namespaces", column: "custom_project_templates_group_id", on_delete: :nullify
add_foreign_key "application_settings", "projects", column: "file_template_project_id", name: "fk_ec757bd087", on_delete: :nullify
add_foreign_key "application_settings", "projects", column: "instance_administration_project_id", on_delete: :nullify
......
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