Initial commit

This commit is contained in:
Yaser
2026-08-13 19:56:46 +03:30
commit de1d57a67b
474 changed files with 43185 additions and 0 deletions

View 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

View 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

View File

@@ -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

View 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

View 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

View 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

View File

@@ -0,0 +1,5 @@
class AddDataFieldToUsersTable < ActiveRecord::Migration[5.2]
def change
add_column :users, :data, :text, null: true, after: :role
end
end

View 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

View 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

View File

@@ -0,0 +1,5 @@
class AddDescriptionToLabels < ActiveRecord::Migration[5.2]
def change
add_column :labels, :description, :string, null: true, after: :scope
end
end

View File

@@ -0,0 +1,5 @@
class AddDefaultStateToProfilesTable < ActiveRecord::Migration[5.2]
def change
change_column_default :profiles, :state, 'drafted'
end
end

View File

@@ -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

View 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

View File

@@ -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

View 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

View 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

View File

@@ -0,0 +1,5 @@
class AddDocCategoryToDocuments < ActiveRecord::Migration[5.2]
def change
add_column :documents, :doc_category, :string
end
end

View 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

View File

@@ -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

View File

@@ -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

View 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

View 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

View File

@@ -0,0 +1,5 @@
class AddNationalCodeToProfiles < ActiveRecord::Migration[5.2]
def change
add_column :profiles, :national_code_encrypted, :string
end
end

View 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

View 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

View 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

View File

@@ -0,0 +1,5 @@
class ChangeCityInProfile < ActiveRecord::Migration[5.2]
def change
add_reference :profiles, :city
end
end

View 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

View 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

View File

@@ -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

213
db/schema.rb Normal file
View File

@@ -0,0 +1,213 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_08_11_064241) do
create_table "activities", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.bigint "user_id", null: false
t.string "target_uid"
t.string "category"
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"
t.timestamp "created_at"
t.index ["target_uid"], name: "index_activities_on_target_uid"
t.index ["user_id"], name: "index_activities_on_user_id"
end
create_table "apikeys", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.bigint "key_holder_account_id", null: false, unsigned: true
t.string "key_holder_account_type", default: "User", null: false
t.string "kid", null: false
t.string "algorithm", null: false
t.string "scope"
t.string "secret_encrypted", limit: 1024
t.string "state", default: "active", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["key_holder_account_type", "key_holder_account_id"], name: "idx_apikey_on_account"
t.index ["kid"], name: "index_apikeys_on_kid", unique: true
end
create_table "cities", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name"
t.bigint "province_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["province_id"], name: "index_cities_on_province_id"
end
create_table "comments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade 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", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id"], name: "index_comments_on_user_id"
end
create_table "data_storages", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.bigint "user_id", null: false, unsigned: true
t.string "title", limit: 64, null: false
t.text "data", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id", "title"], name: "index_data_storages_on_user_id_and_title", unique: true
end
create_table "documents", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.bigint "user_id", null: false, unsigned: true
t.string "upload"
t.string "doc_type"
t.date "doc_expire"
t.string "doc_number_encrypted"
t.bigint "doc_number_index"
t.date "doc_issue"
t.string "doc_category"
t.string "identificator"
t.text "metadata"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "state", default: 0, null: false
t.index ["doc_number_index"], name: "index_documents_on_doc_number_index"
t.index ["user_id"], name: "index_documents_on_user_id"
end
create_table "labels", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade 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.string "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id", "key", "scope"], name: "index_labels_on_user_id_and_key_and_scope"
t.index ["user_id"], name: "index_labels_on_user_id"
end
create_table "levels", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "key", null: false
t.string "value"
t.string "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "permissions", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "action", null: false
t.string "role", null: false
t.string "verb", null: false
t.string "path", null: false
t.string "topic"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["topic"], name: "index_permissions_on_topic"
end
create_table "phones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.integer "user_id", null: false, unsigned: true
t.string "country", null: false
t.string "code", limit: 5
t.string "number_encrypted", null: false
t.bigint "number_index", null: false
t.datetime "validated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "category", null: false
t.integer "state", default: 0
t.integer "step", default: 0
t.index ["number_index"], name: "index_phones_on_number_index"
t.index ["user_id"], name: "index_phones_on_user_id"
end
create_table "profiles", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.bigint "user_id"
t.string "author"
t.string "applicant_id"
t.string "first_name_encrypted", limit: 1024
t.string "last_name_encrypted", limit: 1024
t.string "dob_encrypted"
t.string "address_encrypted", limit: 1024
t.string "postcode"
t.string "city"
t.string "country"
t.integer "state", limit: 1, default: 0, unsigned: true
t.text "metadata"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "national_code_encrypted"
t.bigint "city_id"
t.index ["city_id"], name: "index_profiles_on_city_id"
t.index ["user_id"], name: "index_profiles_on_user_id"
end
create_table "provinces", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "restrictions", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "category", null: false
t.string "scope", limit: 64, null: false
t.string "value", limit: 64, null: false
t.integer "code"
t.string "state", limit: 16, default: "enabled", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "service_accounts", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "uid", null: false
t.bigint "owner_id", 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.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "treasuries", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.bigint "user_id", null: false, unsigned: true
t.string "title", limit: 128
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.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id"], name: "index_treasuries_on_user_id"
end
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade 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.text "data"
t.integer "level", default: 0, null: false
t.boolean "otp", default: false
t.string "state", default: "pending", null: false
t.bigint "referral_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["uid"], name: "index_users_on_uid", unique: true
end
add_foreign_key "cities", "provinces"
end

14
db/seeds.rb Normal file
View File

@@ -0,0 +1,14 @@
# frozen_string_literal: true
require_dependency 'barong/seed'
seed = Barong::Seed.new
seed.seed_levels
seed.seed_permissions
seed.seed_users
seed.seed_superadmin
seed.seed_restrictions
# seed.seed_provinces
# seed.seed_cities
puts seed.inspect

266
db/structure.sql Normal file
View File

@@ -0,0 +1,266 @@
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
DROP TABLE IF EXISTS `activities`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `activities` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) NOT NULL,
`target_uid` varchar(255) DEFAULT NULL,
`category` varchar(255) DEFAULT NULL,
`user_ip` varchar(255) NOT NULL,
`user_agent` varchar(255) NOT NULL,
`topic` varchar(255) NOT NULL,
`action` varchar(255) NOT NULL,
`result` varchar(255) NOT NULL,
`data` text,
`created_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `index_activities_on_user_id` (`user_id`),
KEY `index_activities_on_target_uid` (`target_uid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `apikeys`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `apikeys` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) unsigned NOT NULL,
`kid` varchar(255) NOT NULL,
`algorithm` varchar(255) NOT NULL,
`scope` varchar(255) DEFAULT NULL,
`state` varchar(255) NOT NULL DEFAULT 'active',
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `index_apikeys_on_user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `ar_internal_metadata`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `ar_internal_metadata` (
`key` varchar(255) NOT NULL,
`value` varchar(255) DEFAULT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `comments`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `comments` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) unsigned NOT NULL,
`author_uid` varchar(16) NOT NULL,
`title` varchar(64) NOT NULL,
`data` text NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `index_comments_on_user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `data_storages`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `data_storages` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) unsigned NOT NULL,
`title` varchar(64) NOT NULL,
`data` text NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `index_data_storages_on_user_id_and_title` (`user_id`,`title`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `documents`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `documents` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) unsigned NOT NULL,
`upload` varchar(255) DEFAULT NULL,
`doc_type` varchar(255) DEFAULT NULL,
`doc_number` varchar(255) DEFAULT NULL,
`doc_expire` date DEFAULT NULL,
`identificator` varchar(255) DEFAULT NULL,
`metadata` text,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
`doc_issue` date DEFAULT NULL,
`doc_category` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `index_documents_on_user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `labels`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `labels` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) unsigned NOT NULL,
`key` varchar(255) NOT NULL,
`value` varchar(255) NOT NULL,
`scope` varchar(255) NOT NULL DEFAULT 'public',
`description` varchar(255) DEFAULT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `index_labels_on_user_id` (`user_id`),
KEY `index_labels_on_user_id_and_key_and_scope` (`user_id`,`key`,`scope`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `levels`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `levels` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`key` varchar(255) NOT NULL,
`value` varchar(255) DEFAULT NULL,
`description` varchar(255) DEFAULT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `permissions`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `permissions` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`action` varchar(255) NOT NULL,
`role` varchar(255) NOT NULL,
`verb` varchar(255) NOT NULL,
`path` varchar(255) NOT NULL,
`topic` varchar(255) DEFAULT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `index_permissions_on_topic` (`topic`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `phones`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `phones` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` int(10) unsigned NOT NULL,
`country` varchar(255) NOT NULL,
`number` varchar(255) NOT NULL,
`code` varchar(5) DEFAULT NULL,
`validated_at` datetime DEFAULT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `index_phones_on_user_id` (`user_id`),
KEY `index_phones_on_number` (`number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `profiles`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `profiles` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) DEFAULT NULL,
`author` varchar(255) DEFAULT NULL,
`applicant_id` varchar(255) DEFAULT NULL,
`first_name` varchar(255) DEFAULT NULL,
`last_name` varchar(255) DEFAULT NULL,
`dob` date DEFAULT NULL,
`address` varchar(255) DEFAULT NULL,
`postcode` varchar(255) DEFAULT NULL,
`city` varchar(255) DEFAULT NULL,
`country` varchar(255) DEFAULT NULL,
`state` tinyint(3) unsigned DEFAULT '0',
`metadata` text,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `index_profiles_on_user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `restrictions`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `restrictions` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`category` varchar(255) NOT NULL,
`scope` varchar(64) NOT NULL,
`value` varchar(64) NOT NULL,
`code` int(11) DEFAULT NULL,
`state` varchar(16) NOT NULL DEFAULT 'enabled',
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `schema_migrations`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `schema_migrations` (
`version` varchar(255) NOT NULL,
PRIMARY KEY (`version`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `users`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `users` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`uid` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`password_digest` varchar(255) NOT NULL,
`role` varchar(255) NOT NULL DEFAULT 'member',
`data` text,
`level` int(11) NOT NULL DEFAULT '0',
`otp` tinyint(1) DEFAULT '0',
`state` varchar(255) NOT NULL DEFAULT 'pending',
`referral_id` bigint(20) DEFAULT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `index_users_on_uid` (`uid`),
UNIQUE KEY `index_users_on_email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
INSERT INTO `schema_migrations` (version) VALUES
('20181101143041'),
('20181115100105'),
('20190108115333'),
('20190318133453'),
('20190529114214'),
('20190813112503'),
('20190827080317'),
('20190902032709'),
('20191122151630'),
('20191210090006'),
('20200318152130'),
('20200429082843'),
('20200514123908'),
('20200602075906'),
('20200609144734'),
('20200701115721');