Commit 00eb49d0 authored by Kamil Trzciński's avatar Kamil Trzciński

Add simple data models

parent b74defff
......@@ -266,6 +266,9 @@ class Project < ActiveRecord::Base
has_many :project_deploy_tokens
has_many :deploy_tokens, through: :project_deploy_tokens
has_many :project_feature_flags
has_many :project_feature_flags_access_tokens
has_one :auto_devops, class_name: 'ProjectAutoDevops'
has_many :custom_attributes, class_name: 'ProjectCustomAttribute'
......
class ProjectFeatureFlag < ActiveRecord::Base
belongs_to :project
validates :project, presence: true
validates :name,
presence: true,
length: 2..63,
format: {
with: Gitlab::Regex.feature_flag_regex,
message: Gitlab::Regex.feature_flag_regex_message
}
end
class ProjectFeatureFlagAccessToken < ActiveRecord::Base
include TokenAuthenticatable
belongs_to :project
validates :project, presence: true
validates :token, presence: true
add_authentication_token_field :token
end
class AddFeatureFlagsToProjects < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME = false
def change
create_table :project_feature_flags do |t|
t.integer :project_id, null: false
t.datetime_with_timezone :created_at, null: false
t.datetime_with_timezone :updated_at, null: false
t.string :name, null: false
t.text :description
t.boolean :active, null: false
t.foreign_key :projects, column: :project_id, on_delete: :cascade
t.index [:project_id, :name], unique: true
end
create_table :project_feature_flag_access_tokens do |t|
t.integer :project_id, null: false
t.string :token, null: false
t.index [:project_id, :token], unique: true, name: :project_feature_flag_access_token
t.foreign_key :projects, column: :project_id, on_delete: :cascade
end
end
end
......@@ -71,6 +71,15 @@ module Gitlab
"Must start with a letter, and cannot end with '-'"
end
def feature_flag_regex
/\A[a-z]([-a-z0-9]*[a-z0-9])?\z/
end
def feature_flag_regex_message
"can contain only lowercase letters, digits, '_' and '-'. " \
"Must start with a letter, and cannot end with '-'"
end
def build_trace_section_regex
@build_trace_section_regexp ||= /section_((?:start)|(?:end)):(\d+):([a-zA-Z0-9_.-]+)\r\033\[0K/.freeze
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