Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create migrations(tables) [1pt] #17

Merged
merged 5 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ default: &default
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: postgres
password: <%= ENV["DB_PASSWORD"] %>

development:
<<: *default
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20230626122939_create_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateUsers < ActiveRecord::Migration[7.0]
def change
create_table :users do |t|
t.string :name

t.timestamps
end
end
end
12 changes: 12 additions & 0 deletions db/migrate/20230626124248_create_foods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateFoods < ActiveRecord::Migration[7.0]
def change
create_table :foods do |t|
t.string :name
t.string :measurement_unit
t.decimal :price
t.integer :quantity

t.timestamps
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20230626124654_add_user_ref_to_foods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddUserRefToFoods < ActiveRecord::Migration[7.0]
def change
add_reference :foods, :user, null: false, foreign_key: true
end
end
13 changes: 13 additions & 0 deletions db/migrate/20230626125519_create_recipes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateRecipes < ActiveRecord::Migration[7.0]
def change
create_table :recipes do |t|
t.string :name
t.integer :preparation_time
t.integer :cooking_time
t.text :description
t.boolean :public

t.timestamps
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20230626125630_add_user_ref_to_recipes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddUserRefToRecipes < ActiveRecord::Migration[7.0]
def change
add_reference :recipes, :user, null: false, foreign_key: true
end
end
9 changes: 9 additions & 0 deletions db/migrate/20230626130009_create_recipe_foods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateRecipeFoods < ActiveRecord::Migration[7.0]
def change
create_table :recipe_foods do |t|
t.integer :quantity

t.timestamps
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20230626130114_add_recipe_ref_to_recipe_foods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddRecipeRefToRecipeFoods < ActiveRecord::Migration[7.0]
def change
add_reference :recipe_foods, :recipe, null: false, foreign_key: true
end
end
5 changes: 5 additions & 0 deletions db/migrate/20230626130217_add_food_ref_to_recipe_foods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddFoodRefToRecipeFoods < ActiveRecord::Migration[7.0]
def change
add_reference :recipe_foods, :food, null: false, foreign_key: true
end
end
60 changes: 60 additions & 0 deletions db/schema.rb

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