Добавление миграций БД и моделей
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
class Auditor < ApplicationRecord
|
||||
has_many :yearly_files, dependent: :nullify
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class DocumentType < ApplicationRecord
|
||||
has_many :financial_statements, dependent: :restrict_with_error
|
||||
|
||||
validates :name, presence: true
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class FinancialStatement < ApplicationRecord
|
||||
belongs_to :yearly_file
|
||||
belongs_to :document_type
|
||||
|
||||
validates :data, presence: true
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class Organization < ApplicationRecord
|
||||
has_many :yearly_files, dependent: :destroy
|
||||
has_many :financial_statements, through: :yearly_files
|
||||
|
||||
validates :inn, presence: true
|
||||
end
|
||||
@@ -0,0 +1,10 @@
|
||||
class YearlyFile < ApplicationRecord
|
||||
belongs_to :organization
|
||||
belongs_to :auditor, optional: true
|
||||
|
||||
has_many :financial_statements, dependent: :destroy
|
||||
|
||||
has_one_attached :file
|
||||
|
||||
validates :year, presence: true
|
||||
end
|
||||
@@ -0,0 +1,18 @@
|
||||
class CreateOrganizations < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :organizations do |t|
|
||||
t.string :inn, null: false
|
||||
t.string :full_name
|
||||
t.string :kpp
|
||||
t.string :okpo
|
||||
t.string :okfs
|
||||
t.string :okopf
|
||||
t.string :okved2
|
||||
t.string :address
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :organizations, :inn
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,13 @@
|
||||
class CreateAuditors < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :auditors do |t|
|
||||
t.string :name
|
||||
t.string :inn
|
||||
t.string :ogrn
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :auditors, :inn
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
class CreateDocumentTypes < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :document_types do |t|
|
||||
t.string :name, null: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
class CreateYearlyFiles < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :yearly_files do |t|
|
||||
t.references :organization, null: false, foreign_key: true
|
||||
t.integer :year, null: false
|
||||
t.references :auditor, foreign_key: true
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,12 @@
|
||||
class CreateFinancialStatements < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :financial_statements do |t|
|
||||
t.references :yearly_file, null: false, foreign_key: true
|
||||
t.references :document_type, null: false, foreign_key: true
|
||||
t.integer :sheet_number
|
||||
t.jsonb :data, default: {}
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
Generated
+55
-1
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.1].define(version: 2025_12_09_142642) do
|
||||
ActiveRecord::Schema[7.1].define(version: 2026_03_12_000005) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
@@ -42,6 +42,46 @@ ActiveRecord::Schema[7.1].define(version: 2025_12_09_142642) do
|
||||
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
|
||||
end
|
||||
|
||||
create_table "auditors", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "inn"
|
||||
t.string "ogrn"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["inn"], name: "index_auditors_on_inn"
|
||||
end
|
||||
|
||||
create_table "document_types", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "financial_statements", force: :cascade do |t|
|
||||
t.bigint "yearly_file_id", null: false
|
||||
t.bigint "document_type_id", null: false
|
||||
t.integer "sheet_number"
|
||||
t.jsonb "data", default: {}
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["document_type_id"], name: "index_financial_statements_on_document_type_id"
|
||||
t.index ["yearly_file_id"], name: "index_financial_statements_on_yearly_file_id"
|
||||
end
|
||||
|
||||
create_table "organizations", force: :cascade do |t|
|
||||
t.string "inn", null: false
|
||||
t.string "full_name"
|
||||
t.string "kpp"
|
||||
t.string "okpo"
|
||||
t.string "okfs"
|
||||
t.string "okopf"
|
||||
t.string "okved2"
|
||||
t.string "address"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["inn"], name: "index_organizations_on_inn"
|
||||
end
|
||||
|
||||
create_table "reports", force: :cascade do |t|
|
||||
t.string "inn"
|
||||
t.string "status"
|
||||
@@ -76,6 +116,20 @@ ActiveRecord::Schema[7.1].define(version: 2025_12_09_142642) do
|
||||
t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"
|
||||
end
|
||||
|
||||
create_table "yearly_files", force: :cascade do |t|
|
||||
t.bigint "organization_id", null: false
|
||||
t.integer "year", null: false
|
||||
t.bigint "auditor_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["auditor_id"], name: "index_yearly_files_on_auditor_id"
|
||||
t.index ["organization_id"], name: "index_yearly_files_on_organization_id"
|
||||
end
|
||||
|
||||
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
|
||||
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
|
||||
add_foreign_key "financial_statements", "document_types"
|
||||
add_foreign_key "financial_statements", "yearly_files"
|
||||
add_foreign_key "yearly_files", "auditors"
|
||||
add_foreign_key "yearly_files", "organizations"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user