Skip to content

Commit

Permalink
Seed database
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioHincapie committed Oct 7, 2022
1 parent 1d5cee3 commit 0fd536b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 17 deletions.
4 changes: 2 additions & 2 deletions app/models/clasification.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Clasification < ApplicationRecord
belongs_to :movements
belongs_to :categories
belongs_to :movement
belongs_to :category
end
4 changes: 2 additions & 2 deletions db/migrate/20221006204943_create_clasifications.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 6 additions & 6 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 47 additions & 7 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 0fd536b

Please sign in to comment.