add balance entity
This commit is contained in:
13
db/migrate/20210811121726_create_balances.rb
Normal file
13
db/migrate/20210811121726_create_balances.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
class CreateBalances < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
create_table(:balances) do |t|
|
||||
t.references(:user, null: false, foreign_key: true)
|
||||
t.references(:currency, null: false, foreign_key: true)
|
||||
|
||||
t.decimal(:amount, precision: 20, scale: 10, null: false, default: 0)
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
14
db/schema.rb
generated
14
db/schema.rb
generated
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2021_08_11_014107) do
|
||||
ActiveRecord::Schema.define(version: 2021_08_11_121726) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -55,6 +55,16 @@ ActiveRecord::Schema.define(version: 2021_08_11_014107) do
|
||||
t.index ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true
|
||||
end
|
||||
|
||||
create_table "balances", force: :cascade do |t|
|
||||
t.bigint "user_id", null: false
|
||||
t.bigint "currency_id", null: false
|
||||
t.decimal "amount", precision: 20, scale: 10, default: "0.0", null: false
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.index ["currency_id"], name: "index_balances_on_currency_id"
|
||||
t.index ["user_id"], name: "index_balances_on_user_id"
|
||||
end
|
||||
|
||||
create_table "currencies", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
@@ -85,5 +95,7 @@ ActiveRecord::Schema.define(version: 2021_08_11_014107) do
|
||||
|
||||
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 "balances", "currencies"
|
||||
add_foreign_key "balances", "users"
|
||||
add_foreign_key "user_documents", "users"
|
||||
end
|
||||
|
||||
24
db/seeds.rb
24
db/seeds.rb
@@ -1,8 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
# This file should contain all the record creation needed to seed the database with its default values.
|
||||
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
|
||||
# Character.create(name: 'Luke', movie: movies.first)
|
||||
|
||||
AdminUser.create(email: "admin@example.com", password: "password")
|
||||
|
||||
user = User.create!(
|
||||
first_name: "Test",
|
||||
last_name: "User",
|
||||
email: "user@example.com",
|
||||
password: "password"
|
||||
)
|
||||
|
||||
currency = Currency.create!(name: "CAKE")
|
||||
|
||||
Balance.create!(
|
||||
user_id: user.id,
|
||||
currency_id: currency.id,
|
||||
amount: 153124.72088
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user