From 24c39f331ae5d1346583b35eece943ead0392bc5 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sat, 30 Nov 2024 19:24:59 +0100 Subject: [PATCH] Define a simple wedding model --- app/models/wedding.rb | 18 ++++++++++++++++++ db/migrate/20241130182228_create_weddings.rb | 10 ++++++++++ db/schema.rb | 12 +++++++++--- db/seeds.rb | 4 ++++ spec/factories/weddings.rb | 5 +++++ spec/models/wedding_spec.rb | 5 +++++ 6 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 app/models/wedding.rb create mode 100644 db/migrate/20241130182228_create_weddings.rb create mode 100644 spec/factories/weddings.rb create mode 100644 spec/models/wedding_spec.rb diff --git a/app/models/wedding.rb b/app/models/wedding.rb new file mode 100644 index 0000000..32c5578 --- /dev/null +++ b/app/models/wedding.rb @@ -0,0 +1,18 @@ +# == Schema Information +# +# Table name: weddings +# +# id :uuid not null, primary key +# date :date not null +# slug :string not null +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_weddings_on_slug (slug) UNIQUE +# +class Wedding < ApplicationRecord + validates :date, presence: true + validates :slug, presence: true, uniqueness: true +end diff --git a/db/migrate/20241130182228_create_weddings.rb b/db/migrate/20241130182228_create_weddings.rb new file mode 100644 index 0000000..c8cf1fd --- /dev/null +++ b/db/migrate/20241130182228_create_weddings.rb @@ -0,0 +1,10 @@ +class CreateWeddings < ActiveRecord::Migration[8.0] + def change + create_table :weddings, id: :uuid do |t| + t.string :slug, null: false, index: { unique: true } + t.date :date, null: false + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 6e9d747..41896ca 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,5 +1,3 @@ -# Copyright (C) 2024 Manuel Bustillo - # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -12,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2024_11_30_095753) do +ActiveRecord::Schema[8.0].define(version: 2024_11_30_182228) do # These are extensions that must be enabled in order to support this database enable_extension "pg_catalog.plpgsql" @@ -208,6 +206,14 @@ ActiveRecord::Schema[8.0].define(version: 2024_11_30_095753) do t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true end + create_table "weddings", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.string "slug", null: false + t.date "date", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["slug"], name: "index_weddings_on_slug", unique: true + end + add_foreign_key "groups", "groups", column: "parent_id" add_foreign_key "guests", "groups" add_foreign_key "seats", "guests" diff --git a/db/seeds.rb b/db/seeds.rb index 42c175e..e7e414d 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -7,6 +7,10 @@ Expense.delete_all Guest.delete_all Group.delete_all +Wedding.delete_all + +Wedding.create!(date: 1.year.from_now) + Expense.create!(name: 'Photographer', amount: 3000, pricing_type: 'fixed') Expense.create!(name: 'Country house', amount: 6000, pricing_type: 'fixed') Expense.create!(name: 'Catering', amount: 200, pricing_type: 'per_person') diff --git a/spec/factories/weddings.rb b/spec/factories/weddings.rb new file mode 100644 index 0000000..5528d3b --- /dev/null +++ b/spec/factories/weddings.rb @@ -0,0 +1,5 @@ +FactoryBot.define do + factory :wedding do + date { 1.year.from_now } + end +end diff --git a/spec/models/wedding_spec.rb b/spec/models/wedding_spec.rb new file mode 100644 index 0000000..8725ba8 --- /dev/null +++ b/spec/models/wedding_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Wedding, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end