# frozen_string_literal: true class InitialDatabase < ActiveRecord::Migration[7.0] def change ############################# # Permissions create_table :permissions do |t| t.string :name t.bigint :value t.timestamps null: false t.index :name, unique: true t.index :value, unique: true end ############################# # Roles create_table :roles do |t| t.uuid :public_id, null: false t.string :name, null: false t.bigint :value, null: false t.bigint :permissions, null: false t.timestamps null: false t.index :public_id, unique: true t.index :name, unique: true t.index :value, unique: true end ############################# # Users create_table :users do |t| t.uuid :public_id, null: false t.references :role, foreign_key: true t.string :username, null: false t.string :encrypted_password, null: false t.boolean :guest, default: false t.integer :sign_in_count, default: 0, null: false t.string :current_sign_in_ip t.string :last_sign_in_ip t.datetime :current_sign_in_at t.datetime :last_sign_in_at t.datetime :remember_created_at t.timestamps null: false t.index :public_id, unique: true t.index :username, unique: true end ############################# # File create_table :files do |t| t.uuid :public_id, null: false t.string :file_name, null: false t.string :file_type, null: false t.timestamps null: false t.index :public_id, unique: true end ############################# # Posts create_table :posts do |t| t.uuid :public_id, null: false t.references :created_by_user, foreign_key: {to_table: :users} t.bigint :role_visibility t.integer :status t.text :title, null: false t.text :content, limit: 1.gigabytes - 1.byte t.timestamps null: false t.datetime :posted_at t.index :public_id, unique: true end ############################# # Post Files create_table :post_files do |t| t.belongs_to :post t.belongs_to :file t.timestamps null: false end end end