diff options
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20230412015748_create_orders.rb | 10 | ||||
-rw-r--r-- | db/migrate/20230412015828_create_payments.rb | 11 | ||||
-rw-r--r-- | db/migrate/20230412015843_add_payment_to_order.rb | 7 | ||||
-rw-r--r-- | db/migrate/20230412020105_create_product_orders.rb | 11 | ||||
-rw-r--r-- | db/schema.rb | 44 |
5 files changed, 78 insertions, 5 deletions
diff --git a/db/migrate/20230412015748_create_orders.rb b/db/migrate/20230412015748_create_orders.rb new file mode 100644 index 0000000..db8ea6f --- /dev/null +++ b/db/migrate/20230412015748_create_orders.rb @@ -0,0 +1,10 @@ +class CreateOrders < ActiveRecord::Migration[7.0] + def change + create_table :orders do |t| + t.references :user_account, null: false, foreign_key: true + t.string :public_id + + t.timestamps + end + end +end diff --git a/db/migrate/20230412015828_create_payments.rb b/db/migrate/20230412015828_create_payments.rb new file mode 100644 index 0000000..d3adeaa --- /dev/null +++ b/db/migrate/20230412015828_create_payments.rb @@ -0,0 +1,11 @@ +class CreatePayments < ActiveRecord::Migration[7.0] + def change + create_table :payments do |t| + t.references :order, null: false, foreign_key: true + t.references :card, null: false, foreign_key: true + t.float :total + + t.timestamps + end + end +end diff --git a/db/migrate/20230412015843_add_payment_to_order.rb b/db/migrate/20230412015843_add_payment_to_order.rb new file mode 100644 index 0000000..90caab6 --- /dev/null +++ b/db/migrate/20230412015843_add_payment_to_order.rb @@ -0,0 +1,7 @@ +class AddPaymentToOrder < ActiveRecord::Migration[7.0] + def change + change_table(:orders) do |t| + t.references :payment, null: false, foreign_key: true + end + end +end diff --git a/db/migrate/20230412020105_create_product_orders.rb b/db/migrate/20230412020105_create_product_orders.rb new file mode 100644 index 0000000..1b2494b --- /dev/null +++ b/db/migrate/20230412020105_create_product_orders.rb @@ -0,0 +1,11 @@ +class CreateProductOrders < ActiveRecord::Migration[7.0] + def change + create_table :product_orders do |t| + t.references :order, null: false, foreign_key: true + t.references :product, null: false, foreign_key: true + t.integer :quantity + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 6a0f312..4564cc7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_04_05_015505) do +ActiveRecord::Schema[7.0].define(version: 2023_04_12_020105) do create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false @@ -76,6 +76,26 @@ ActiveRecord::Schema[7.0].define(version: 2023_04_05_015505) do t.datetime "updated_at", null: false end + create_table "orders", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| + t.bigint "user_account_id", null: false + t.string "public_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "payment_id", null: false + t.index ["payment_id"], name: "index_orders_on_payment_id" + t.index ["user_account_id"], name: "index_orders_on_user_account_id" + end + + create_table "payments", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| + t.bigint "order_id", null: false + t.bigint "card_id", null: false + t.float "total" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["card_id"], name: "index_payments_on_card_id" + t.index ["order_id"], name: "index_payments_on_order_id" + end + create_table "product_carts", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| t.integer "quantity" t.bigint "cart_id" @@ -87,6 +107,16 @@ ActiveRecord::Schema[7.0].define(version: 2023_04_05_015505) do t.index ["product_id"], name: "index_product_carts_on_product_id" end + create_table "product_orders", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| + t.bigint "order_id", null: false + t.bigint "product_id", null: false + t.integer "quantity" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["order_id"], name: "index_product_orders_on_order_id" + t.index ["product_id"], name: "index_product_orders_on_product_id" + end + create_table "product_reviews", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| t.bigint "user_account_id", null: false t.bigint "product_id", null: false @@ -113,10 +143,10 @@ ActiveRecord::Schema[7.0].define(version: 2023_04_05_015505) do end create_table "user_account_addresses", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| - t.bigint "user_account_id", null: false - t.bigint "address_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.bigint "user_account_id" + t.bigint "address_id" t.index ["address_id", "user_account_id"], name: "index_user_account_addresses_on_address_id_and_user_account_id", unique: true t.index ["address_id"], name: "index_user_account_addresses_on_address_id" t.index ["user_account_id"], name: "index_user_account_addresses_on_user_account_id" @@ -139,10 +169,14 @@ ActiveRecord::Schema[7.0].define(version: 2023_04_05_015505) do add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "cards", "user_accounts" add_foreign_key "carts", "user_accounts" + add_foreign_key "orders", "payments" + add_foreign_key "orders", "user_accounts" + add_foreign_key "payments", "cards" + add_foreign_key "payments", "orders" + add_foreign_key "product_orders", "orders" + add_foreign_key "product_orders", "products" add_foreign_key "product_reviews", "products" add_foreign_key "product_reviews", "user_accounts" add_foreign_key "products", "companies" - add_foreign_key "user_account_addresses", "addresses" - add_foreign_key "user_account_addresses", "user_accounts" add_foreign_key "user_accounts", "carts" end |