From 0fd536b7f9f13d689bf10df63e22b967a87143ec Mon Sep 17 00:00:00 2001 From: AntonioHincapie Date: Fri, 7 Oct 2022 12:42:56 -0500 Subject: [PATCH] Seed database --- app/models/clasification.rb | 4 +- .../20221006204943_create_clasifications.rb | 4 +- db/schema.rb | 12 ++--- db/seeds.rb | 54 ++++++++++++++++--- 4 files changed, 57 insertions(+), 17 deletions(-) diff --git a/app/models/clasification.rb b/app/models/clasification.rb index 34801f8..ae7d3d8 100644 --- a/app/models/clasification.rb +++ b/app/models/clasification.rb @@ -1,4 +1,4 @@ class Clasification < ApplicationRecord - belongs_to :movements - belongs_to :categories + belongs_to :movement + belongs_to :category end diff --git a/db/migrate/20221006204943_create_clasifications.rb b/db/migrate/20221006204943_create_clasifications.rb index f8448c8..0a52ff3 100644 --- a/db/migrate/20221006204943_create_clasifications.rb +++ b/db/migrate/20221006204943_create_clasifications.rb @@ -1,8 +1,8 @@ class CreateClasifications < ActiveRecord::Migration[7.0] def change create_table :clasifications do |t| - t.references :movements, null: false, foreign_key: true - t.references :categories, null: false, foreign_key: true + t.belongs_to :movement, null: false, foreign_key: true + t.belongs_to :category, null: false, foreign_key: true t.timestamps end diff --git a/db/schema.rb b/db/schema.rb index 9fbac31..88f84f7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -24,12 +24,12 @@ end create_table "clasifications", force: :cascade do |t| - t.bigint "movements_id", null: false - t.bigint "categories_id", null: false + t.bigint "movement_id", null: false + t.bigint "category_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.index ["categories_id"], name: "index_clasifications_on_categories_id" - t.index ["movements_id"], name: "index_clasifications_on_movements_id" + t.index ["category_id"], name: "index_clasifications_on_category_id" + t.index ["movement_id"], name: "index_clasifications_on_movement_id" end create_table "movements", force: :cascade do |t| @@ -58,7 +58,7 @@ end add_foreign_key "categories", "users" - add_foreign_key "clasifications", "categories", column: "categories_id" - add_foreign_key "clasifications", "movements", column: "movements_id" + add_foreign_key "clasifications", "categories" + add_foreign_key "clasifications", "movements" add_foreign_key "movements", "users" end diff --git a/db/seeds.rb b/db/seeds.rb index bc25fce..26b94d8 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,7 +1,47 @@ -# 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) +first_user = User.create(name: 'Antonio', email: 'antonio@mail.com') +first_user.password = 'pass1234' +first_user.password_confirmation = 'pass1234' +first_user.save + +second_user = User.create(name: 'Gloria', email: 'gloria@mail.com') +second_user.password = 'pass1234' +second_user.password_confirmation = 'pass1234' +second_user.save + +third_user = User.create(name: 'William', email: 'william@mail.com') +third_user.password = 'pass1234' +third_user.password_confirmation = 'pass1234' +third_user.save + +category1 = Category.create(name: 'Bank', icon: 'icon', user_id: first_user.id) +category2 = Category.create(name: 'Credit Card', icon: 'icon', user_id: first_user.id) +category3 = Category.create(name: 'Debit Card', icon: 'icon', user_id: second_user.id) +category4 = Category.create(name: 'Cash', icon: 'icon', user_id: second_user.id) +category5 = Category.create(name: 'Loan', icon: 'icon', user_id: third_user.id) +category6 = Category.create(name: 'Account', icon: 'icon', user_id: third_user.id) + +movement1 = Movement.create(name: 'Taxes', amount: 150.00, user_id: first_user.id) +movement2 = Movement.create(name: 'Groceries', amount: 12.06, user_id: first_user.id) +movement3 = Movement.create(name: 'Gift Card', amount: 50.00, user_id: first_user.id) +movement4 = Movement.create(name: 'Dinner', amount: 100.00, user_id: first_user.id) +movement5 = Movement.create(name: 'Oil', amount: 40.43, user_id: second_user.id) +movement6 = Movement.create(name: 'Parking', amount: 20.00, user_id: second_user.id) +movement7 = Movement.create(name: 'Fruits', amount: 12.50, user_id: second_user.id) +movement8 = Movement.create(name: 'Coffee', amount: 4.50, user_id: second_user.id) +movement9 = Movement.create(name: 'First Month', amount: 300.00, user_id: third_user.id) +movement10 = Movement.create(name: 'Second Month', amount: 400.00, user_id: third_user.id) +movement11 = Movement.create(name: 'Car Bill', amount: 250.00, user_id: third_user.id) +movement12 = Movement.create(name: 'House Bill', amount: 500.00, user_id: third_user.id) + +Clasification.create(movement_id: movement1.id, category_id: category1.id) +Clasification.create(movement_id: movement2.id, category_id: category1.id) +Clasification.create(movement_id: movement3.id, category_id: category2.id) +Clasification.create(movement_id: movement4.id, category_id: category2.id) +Clasification.create(movement_id: movement5.id, category_id: category3.id) +Clasification.create(movement_id: movement6.id, category_id: category3.id) +Clasification.create(movement_id: movement7.id, category_id: category4.id) +Clasification.create(movement_id: movement8.id, category_id: category4.id) +Clasification.create(movement_id: movement9.id, category_id: category5.id) +Clasification.create(movement_id: movement10.id, category_id: category5.id) +Clasification.create(movement_id: movement11.id, category_id: category6.id) +Clasification.create(movement_id: movement12.id, category_id: category6.id)