Commit 4670fc0e authored by Adam Hegyi's avatar Adam Hegyi Committed by Andreas Brandl

Database table for language trends over time

- Introduce new DB table for tracking language trend over time.
- Initial model for Analytics::LanguageTrend::RepositoryLanguage
parent 1772a7b2
---
title: Database table for tracking programming language trends over time
merge_request: 16491
author:
type: added
# frozen_string_literal: true
class CreateAnalyticsLanguageTrendRepositoryLanguages < ActiveRecord::Migration[5.2]
DOWNTIME = false
INDEX_PREFIX = 'analytics_repository_languages_'
def change
create_table :analytics_language_trend_repository_languages, id: false do |t|
t.integer :file_count, null: false, default: 0
t.references :programming_language, {
null: false,
foreign_key: { on_delete: :cascade },
index: false
}
t.references :project, {
null: false,
foreign_key: { on_delete: :cascade },
index: { name: INDEX_PREFIX + 'on_project_id' }
}
t.integer :loc, null: false, default: 0
t.integer :bytes, null: false, default: 0
# Storing percentage (with 2 decimal places), on 2 bytes.
# 50.25% => 5025
# Max: 100.00% => 10000 (fits smallint: 32767)
t.integer :percentage, limit: 2, null: false, default: 0
t.date :snapshot_date, null: false
end
add_index :analytics_language_trend_repository_languages, %I[
programming_language_id
project_id
snapshot_date
], name: INDEX_PREFIX + 'unique_index', unique: true
end
end
......@@ -81,6 +81,18 @@ ActiveRecord::Schema.define(version: 2019_09_12_061145) do
t.index ["start_event_label_id"], name: "index_analytics_ca_project_stages_on_start_event_label_id"
end
create_table "analytics_language_trend_repository_languages", id: false, force: :cascade do |t|
t.integer "file_count", default: 0, null: false
t.bigint "programming_language_id", null: false
t.bigint "project_id", null: false
t.integer "loc", default: 0, null: false
t.integer "bytes", default: 0, null: false
t.integer "percentage", limit: 2, default: 0, null: false
t.date "snapshot_date", null: false
t.index ["programming_language_id", "project_id", "snapshot_date"], name: "analytics_repository_languages_unique_index", unique: true
t.index ["project_id"], name: "analytics_repository_languages_on_project_id"
end
create_table "appearances", id: :serial, force: :cascade do |t|
t.string "title", null: false
t.text "description", null: false
......@@ -3762,6 +3774,8 @@ ActiveRecord::Schema.define(version: 2019_09_12_061145) do
add_foreign_key "analytics_cycle_analytics_project_stages", "labels", column: "end_event_label_id", on_delete: :cascade
add_foreign_key "analytics_cycle_analytics_project_stages", "labels", column: "start_event_label_id", on_delete: :cascade
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 "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
......
# frozen_string_literal: true
module Analytics::LanguageTrend
def self.table_name_prefix
'analytics_language_trend_'
end
end
# frozen_string_literal: true
class Analytics::LanguageTrend::RepositoryLanguage < ApplicationRecord
belongs_to :programming_language
belongs_to :project
end
# frozen_string_literal: true
require 'spec_helper'
describe Analytics::LanguageTrend::RepositoryLanguage do
describe 'associations' do
it { is_expected.to belong_to(:programming_language) }
it { is_expected.to belong_to(:project) }
end
end
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