summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/order.rb10
-rw-r--r--app/models/payment.rb8
-rw-r--r--app/models/product.rb2
-rw-r--r--app/models/product_order.rb8
-rw-r--r--db/migrate/20230412015748_create_orders.rb10
-rw-r--r--db/migrate/20230412015828_create_payments.rb11
-rw-r--r--db/migrate/20230412015843_add_payment_to_order.rb7
-rw-r--r--db/migrate/20230412020105_create_product_orders.rb11
-rw-r--r--db/schema.rb44
9 files changed, 106 insertions, 5 deletions
diff --git a/app/models/order.rb b/app/models/order.rb
new file mode 100644
index 0000000..ae5a0d5
--- /dev/null
+++ b/app/models/order.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+# Order
+# public_id: string
+class Order < ApplicationRecord
+ belongs_to :user_account
+ has_one :payment
+ has_many :product_orders
+ has_many :products, through: :product_orders
+end
diff --git a/app/models/payment.rb b/app/models/payment.rb
new file mode 100644
index 0000000..5d5e862
--- /dev/null
+++ b/app/models/payment.rb
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+# Payment
+# total: float
+class Payment < ApplicationRecord
+ has_one :order
+ belongs_to :card
+end
diff --git a/app/models/product.rb b/app/models/product.rb
index c4514a2..51d6c57 100644
--- a/app/models/product.rb
+++ b/app/models/product.rb
@@ -14,6 +14,8 @@ class Product < ApplicationRecord
has_many :product_reviews
has_many :product_carts
has_many :carts, through: :product_carts
+ has_many :product_orders
+ has_many :orders, through: :product_orders
validates :name, presence: true
validates :unitary_price, presence: true
diff --git a/app/models/product_order.rb b/app/models/product_order.rb
new file mode 100644
index 0000000..004f8fc
--- /dev/null
+++ b/app/models/product_order.rb
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+# ProductOrder
+# quantity: integer
+class ProductOrder < ApplicationRecord
+ belongs_to :order
+ belongs_to :product
+end
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