Initial commit
This commit is contained in:
81
db/migrate/20181101143041_create_all_tables.rb
Normal file
81
db/migrate/20181101143041_create_all_tables.rb
Normal file
@@ -0,0 +1,81 @@
|
||||
class CreateAllTables < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
|
||||
create_table :users do |t|
|
||||
t.string :uid, null: false
|
||||
t.string :email, null: false
|
||||
t.string :password_digest, null: false
|
||||
t.string :role, default: "member", null: false
|
||||
t.integer :level, default: 0, null: false
|
||||
t.boolean :otp, default: false
|
||||
t.string :state, default: "pending", null: false
|
||||
t.timestamps
|
||||
end
|
||||
add_index :users, :uid, unique: true
|
||||
add_index :users, :email, unique: true
|
||||
|
||||
create_table :apikeys do |t|
|
||||
t.bigint :user_id, null: false, unsigned: true
|
||||
t.string :kid, null: false
|
||||
t.string :algorithm, null: false
|
||||
t.string :scope
|
||||
t.string :state, default: "active", null: false
|
||||
t.timestamps
|
||||
t.index [:user_id]
|
||||
end
|
||||
|
||||
create_table :documents do |t|
|
||||
t.bigint :user_id, null: false, unsigned: true
|
||||
t.string :upload
|
||||
t.string :doc_type
|
||||
t.string :doc_number
|
||||
t.date :doc_expire
|
||||
t.text :metadata
|
||||
t.timestamps
|
||||
t.index [:user_id]
|
||||
end
|
||||
|
||||
create_table :labels do |t|
|
||||
t.bigint :user_id, null: false, unsigned: true
|
||||
t.string :key, null: false
|
||||
t.string :value, null: false
|
||||
t.string :scope, default: "public", null: false
|
||||
t.timestamps
|
||||
t.index [:user_id]
|
||||
t.index [:user_id, :key, :scope]
|
||||
end
|
||||
|
||||
create_table :levels do |t|
|
||||
t.string :key, null: false
|
||||
t.string :value
|
||||
t.string :description
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :phones do |t|
|
||||
t.integer :user_id, null: false, unsigned: true
|
||||
t.string :country, null: false
|
||||
t.string :number, null: false
|
||||
t.string :code, limit: 5
|
||||
t.datetime :validated_at
|
||||
t.timestamps
|
||||
t.index [:user_id]
|
||||
t.index [:number]
|
||||
end
|
||||
|
||||
create_table :profiles do |t|
|
||||
t.bigint :user_id
|
||||
t.string :first_name
|
||||
t.string :last_name
|
||||
t.date :dob
|
||||
t.string :address
|
||||
t.string :postcode
|
||||
t.string :city
|
||||
t.string :country
|
||||
t.text :metadata
|
||||
t.timestamps
|
||||
t.index [:user_id]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
15
db/migrate/20181115100105_create_activities.rb
Normal file
15
db/migrate/20181115100105_create_activities.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
class CreateActivities < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :activities do |t|
|
||||
t.references :user, null: false
|
||||
t.string :user_ip, null: false
|
||||
t.string :user_agent, null: false
|
||||
t.string :topic, null: false
|
||||
t.string :action, null: false
|
||||
t.string :result, null: false
|
||||
t.text :data, null: true
|
||||
|
||||
t.timestamp :created_at # avoid updated_at as records not supposed to be updated
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Add new field due to referral - affiliate relation
|
||||
class AddReferralIdToUsersTable < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :users, :referral_id, :bigint, after: :state
|
||||
end
|
||||
end
|
||||
13
db/migrate/20190318133453_create_permissions.rb
Normal file
13
db/migrate/20190318133453_create_permissions.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class CreatePermissions < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :permissions do |t|
|
||||
|
||||
t.string :action, null: false
|
||||
t.string :role, null: false
|
||||
t.string :verb, null: false
|
||||
t.string :path, null: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
10
db/migrate/20190529114214_changes_in_activities_table.rb
Normal file
10
db/migrate/20190529114214_changes_in_activities_table.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
class ChangesInActivitiesTable < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :activities, :target_uid, :string, after: :user_id
|
||||
add_column :activities, :category, :string, after: :target_uid
|
||||
add_column :permissions, :topic, :string, after: :path
|
||||
|
||||
add_index :activities, :target_uid
|
||||
add_index :permissions, :topic
|
||||
end
|
||||
end
|
||||
12
db/migrate/20190813112503_create_restrictions.rb
Normal file
12
db/migrate/20190813112503_create_restrictions.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
class CreateRestrictions < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :restrictions do |t|
|
||||
|
||||
t.string :scope, limit: 64, null: false
|
||||
t.string :value, limit: 64, null: false
|
||||
t.string :state, limit: 16, default: 'enabled', null: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddDataFieldToUsersTable < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :users, :data, :text, null: true, after: :role
|
||||
end
|
||||
end
|
||||
5
db/migrate/20190902032709_add_state_profiles.rb
Normal file
5
db/migrate/20190902032709_add_state_profiles.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddStateProfiles < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :profiles, :state, :integer, unsigned: true, limit: 1, after: :country
|
||||
end
|
||||
end
|
||||
12
db/migrate/20191122151630_create_data_storages.rb
Normal file
12
db/migrate/20191122151630_create_data_storages.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
class CreateDataStorages < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :data_storages do |t|
|
||||
t.bigint :user_id, null: false, unsigned: true
|
||||
t.string :title, limit: 64, null: false
|
||||
t.text :data, limit: 5120, null: false
|
||||
|
||||
t.timestamps
|
||||
t.index [:user_id, :title], unique: true
|
||||
end
|
||||
end
|
||||
end
|
||||
5
db/migrate/20191210090006_add_description_to_labels.rb
Normal file
5
db/migrate/20191210090006_add_description_to_labels.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddDescriptionToLabels < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :labels, :description, :string, null: true, after: :scope
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddDefaultStateToProfilesTable < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
change_column_default :profiles, :state, 'drafted'
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class AddCodeAndTypeInRestrictionsTable < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :restrictions, :code, :integer, null: true, after: :value
|
||||
add_column :restrictions, :category, :string, null: false, after: :id
|
||||
end
|
||||
end
|
||||
5
db/migrate/20200507104423_add_encrypted_secret.rb
Normal file
5
db/migrate/20200507104423_add_encrypted_secret.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddEncryptedSecret < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :apikeys, :secret_encrypted, :string, limit: 1024, after: :scope
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
class AddIdentificatorToDocumentsTable < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :documents, :identificator, :string, after: :doc_expire
|
||||
add_column :documents, :doc_issue, :date, before: :doc_expire
|
||||
add_column :profiles, :applicant_id, :string, after: :user_id
|
||||
end
|
||||
end
|
||||
5
db/migrate/20200602075906_add_author_to_profiles.rb
Normal file
5
db/migrate/20200602075906_add_author_to_profiles.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddAuthorToProfiles < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :profiles, :author, :string, null: true, after: :user_id
|
||||
end
|
||||
end
|
||||
13
db/migrate/20200609144734_create_comments.rb
Normal file
13
db/migrate/20200609144734_create_comments.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class CreateComments < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :comments do |t|
|
||||
t.bigint :user_id, null: false, unsigned: true
|
||||
t.string :author_uid, limit: 16, null: false
|
||||
t.string :title, limit: 64, null: false
|
||||
t.text :data, limit: 5120, null: false
|
||||
|
||||
t.timestamps
|
||||
t.index :user_id
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddDocCategoryToDocuments < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :documents, :doc_category, :string
|
||||
end
|
||||
end
|
||||
18
db/migrate/20200902125225_make_api_key_kid_unique.rb
Normal file
18
db/migrate/20200902125225_make_api_key_kid_unique.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
class MakeApiKeyKidUnique < ActiveRecord::Migration[5.2]
|
||||
class APIKey < ActiveRecord::Base
|
||||
self.table_name = :apikeys
|
||||
end
|
||||
|
||||
def up
|
||||
duplicated_records = APIKey.select(:kid).group(:kid).having("count(*) > 1")
|
||||
duplicated_records.each do |api_key|
|
||||
APIKey.where(kid: api_key.kid).destroy_all
|
||||
end
|
||||
|
||||
add_index :apikeys, :kid, unique: true unless index_exists?(:apikeys, :kid)
|
||||
end
|
||||
|
||||
def down
|
||||
remove_index :apikeys, :kid if index_exists?(:apikeys, :kid)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,50 @@
|
||||
class AddServiceAccountsAndRelatedChanges < ActiveRecord::Migration[5.2]
|
||||
class APIKey < ActiveRecord::Base
|
||||
self.table_name = :apikeys
|
||||
end
|
||||
|
||||
def up
|
||||
create_table :service_accounts do |t|
|
||||
t.string :uid, null: false
|
||||
t.bigint :owner_id, null: false, unsigned: true
|
||||
t.string :email, null: false
|
||||
t.string :role, default: "service_account", null: false
|
||||
t.integer :level, default: 0, null: false
|
||||
t.string :state, default: "pending", null: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_column :apikeys, :key_holder_account_id, :bigint, null: false, unsigned: true, after: :id
|
||||
add_column :apikeys, :key_holder_account_type, :string, null: false, default: "User", after: :key_holder_account_id
|
||||
|
||||
APIKey.find_each do |api_key|
|
||||
api_key.key_holder_account_type = 'User'
|
||||
api_key.key_holder_account_id = api_key.user_id
|
||||
api_key.save!
|
||||
end
|
||||
|
||||
remove_column :apikeys, :user_id
|
||||
add_index :apikeys, [:key_holder_account_type, :key_holder_account_id], name: :idx_apikey_on_account unless index_exists?(:service_accounts, [:key_holder_account_type, :key_holder_account_id])
|
||||
end
|
||||
|
||||
def down
|
||||
add_column :apikeys, :user_id, :bigint, unsigned: true, null: false, after: :key_holder_account_id
|
||||
|
||||
APIKey.find_each do |api_key|
|
||||
if api_key.key_holder_account_type == 'ServiceAccount'
|
||||
api_key.destroy!
|
||||
next
|
||||
end
|
||||
|
||||
api_key.user_id = api_key.key_holder_account_id
|
||||
api_key.save!
|
||||
end
|
||||
|
||||
remove_column :apikeys, :key_holder_account_id
|
||||
remove_column :apikeys, :key_holder_account_type
|
||||
|
||||
remove_index :service_accounts, column: [:key_holder_account_type, :key_holder_account_id] if index_exists?(:service_accounts, [:key_holder_account_type, :key_holder_account_id])
|
||||
drop_table :service_accounts
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,57 @@
|
||||
class AddEncryptedValuesToPhonesProfilesDocuments < ActiveRecord::Migration[5.2]
|
||||
def up
|
||||
# Phones Table
|
||||
add_column :phones, :number_encrypted, :string, null: false, after: :code
|
||||
add_column :phones, :number_index, :bigint, null: false, after: :number_encrypted
|
||||
add_index :phones, [:number_index]
|
||||
|
||||
remove_column :phones, :number, :string
|
||||
|
||||
# Profiles Table
|
||||
add_column :profiles, :first_name_encrypted, :string, limit: 1024, after: :applicant_id
|
||||
add_column :profiles, :last_name_encrypted, :string, limit: 1024, after: :first_name_encrypted
|
||||
add_column :profiles, :dob_encrypted, :string, after: :last_name_encrypted
|
||||
add_column :profiles, :address_encrypted, :string, limit: 1024, after: :dob_encrypted
|
||||
|
||||
|
||||
remove_column :profiles, :first_name, :string
|
||||
remove_column :profiles, :last_name, :string
|
||||
remove_column :profiles, :dob, :date
|
||||
remove_column :profiles, :address, :string
|
||||
|
||||
# Documents table
|
||||
add_column :documents, :doc_number_encrypted, :string, after: :doc_expire
|
||||
add_column :documents, :doc_number_index, :bigint, after: :doc_number_encrypted
|
||||
add_index :documents, [:doc_number_index]
|
||||
|
||||
remove_column :documents, :doc_number, :string
|
||||
end
|
||||
|
||||
def down
|
||||
# Phones Table
|
||||
add_column :phones, :number, :string, null: false, after: :country
|
||||
|
||||
remove_index :phones, column: :number_index
|
||||
remove_column :phones, :number_encrypted, :string
|
||||
remove_column :phones, :number_index, :bigint
|
||||
|
||||
# Profiles Table
|
||||
add_column :profiles, :first_name, :string, after: :applicant_id
|
||||
add_column :profiles, :last_name, :string, after: :first_name
|
||||
add_column :profiles, :dob, :date, after: :last_name
|
||||
add_column :profiles, :address, :string, after: :dob
|
||||
|
||||
|
||||
remove_column :profiles, :first_name_encrypted, :string
|
||||
remove_column :profiles, :last_name_encrypted, :string
|
||||
remove_column :profiles, :dob_encrypted, :string
|
||||
remove_column :profiles, :address_encrypted, :string
|
||||
|
||||
# Documents table
|
||||
add_column :documents, :doc_number, :string, after: :doc_type
|
||||
|
||||
remove_index :documents, column: :doc_number_index
|
||||
remove_column :documents, :doc_number_encrypted, :string
|
||||
remove_column :documents, :doc_number_index, :bigint
|
||||
end
|
||||
end
|
||||
11
db/migrate/20201001112814_change_document_fields_position.rb
Normal file
11
db/migrate/20201001112814_change_document_fields_position.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class ChangeDocumentFieldsPosition < ActiveRecord::Migration[5.2]
|
||||
def up
|
||||
change_column :documents, :doc_issue, :date, after: :doc_number_index
|
||||
change_column :documents, :doc_category, :string, after: :doc_issue
|
||||
end
|
||||
|
||||
def down
|
||||
change_column :documents, :doc_issue, :date, after: :updated_at
|
||||
change_column :documents, :doc_category, :string, after: :doc_issue
|
||||
end
|
||||
end
|
||||
9
db/migrate/20210218135634_change_owner_id_requirement.rb
Normal file
9
db/migrate/20210218135634_change_owner_id_requirement.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class ChangeOwnerIdRequirement < ActiveRecord::Migration[5.2]
|
||||
def up
|
||||
change_column :service_accounts, :owner_id, :bigint, null: true, unsigned: true
|
||||
end
|
||||
|
||||
def down
|
||||
change_column :service_accounts, :owner_id, :bigint, null: false, unsigned: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddNationalCodeToProfiles < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :profiles, :national_code_encrypted, :string
|
||||
end
|
||||
end
|
||||
21
db/migrate/20210418085508_create_treasuries.rb
Normal file
21
db/migrate/20210418085508_create_treasuries.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
class CreateTreasuries < ActiveRecord::Migration[5.2]
|
||||
def down
|
||||
drop_table :treasuries
|
||||
end
|
||||
|
||||
def up
|
||||
create_table :treasuries do |t|
|
||||
t.bigint :user_id, null: false, unsigned: true
|
||||
t.string :title, limit: 128, null: true
|
||||
t.string :data, null: false
|
||||
t.text :result
|
||||
t.integer :state, default: 0, null: false, unsigned: true
|
||||
t.integer :kind, default: 0, null: false, unsigned: true
|
||||
t.timestamps
|
||||
end
|
||||
add_index :treasuries, :user_id
|
||||
add_index :treasuries, :data, unique: true
|
||||
add_index :treasuries, %i[user_id title], unique: true
|
||||
end
|
||||
end
|
||||
|
||||
12
db/migrate/20210420111532_create_provinces.rb
Normal file
12
db/migrate/20210420111532_create_provinces.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
class CreateProvinces < ActiveRecord::Migration[5.2]
|
||||
def down
|
||||
drop_table :provinces
|
||||
end
|
||||
|
||||
def up
|
||||
create_table :provinces do |t|
|
||||
t.string :name
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
14
db/migrate/20210420111629_create_cities.rb
Normal file
14
db/migrate/20210420111629_create_cities.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
class CreateCities < ActiveRecord::Migration[5.2]
|
||||
def down
|
||||
drop_table :cities
|
||||
end
|
||||
def up
|
||||
create_table :cities do |t|
|
||||
t.string :name
|
||||
t.references :province, foreign_key: true
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
5
db/migrate/20210420113539_change_city_in_profile.rb
Normal file
5
db/migrate/20210420113539_change_city_in_profile.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class ChangeCityInProfile < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_reference :profiles, :city
|
||||
end
|
||||
end
|
||||
13
db/migrate/20210425062048_add_step_to_phone.rb
Normal file
13
db/migrate/20210425062048_add_step_to_phone.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class AddStepToPhone < ActiveRecord::Migration[5.2]
|
||||
def up
|
||||
add_column :phones, :category, :integer, null: false
|
||||
add_column :phones, :state, :integer, null: true, default: 0
|
||||
add_column :phones, :step, :integer, null: true, default: 0
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :phones, :category
|
||||
remove_column :phones, :state
|
||||
remove_column :phones, :step
|
||||
end
|
||||
end
|
||||
9
db/migrate/20210714111301_add_state_to_documents.rb
Normal file
9
db/migrate/20210714111301_add_state_to_documents.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class AddStateToDocuments < ActiveRecord::Migration[5.2]
|
||||
def up
|
||||
add_column :documents, :state, :integer, null: false, default: 0
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :documents, :state
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
class RemoveIndexDataFromTreasuries < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
remove_index :treasuries, name: 'index_treasuries_on_data'
|
||||
remove_index :treasuries, name: 'index_treasuries_on_user_id_and_title'
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user