Skip to content

Commit 83287b5

Browse files
Add models, tables and seeds
1 parent 5a9330a commit 83287b5

File tree

6 files changed

+80
-7
lines changed

6 files changed

+80
-7
lines changed

app/models/monster.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Monster < ApplicationRecord
2+
end

app/models/tweet.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Tweet < ApplicationRecord
2+
belongs_to :monster
3+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class CreateMonsters < ActiveRecord::Migration[7.0]
2+
def change
3+
create_table :monsters do |t|
4+
t.string :name
5+
t.text :description
6+
7+
t.timestamps
8+
end
9+
end
10+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class CreateTweets < ActiveRecord::Migration[7.0]
2+
def change
3+
create_table :tweets do |t|
4+
t.string :content
5+
t.references :monster, null: false, foreign_key: true
6+
7+
t.timestamps
8+
end
9+
end
10+
end

db/schema.rb

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

db/seeds.rb

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1-
# This file should contain all the record creation needed to seed the database with its default values.
2-
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
3-
#
4-
# Examples:
5-
#
6-
# movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }])
7-
# Character.create(name: "Luke", movie: movies.first)
1+
Tweet.destroy_all
2+
Monster.destroy_all
3+
4+
# Start IDs sequence at 1 for both monsters and tweets tables
5+
ActiveRecord::Base.connection.execute("ALTER SEQUENCE monsters_id_seq RESTART WITH 1")
6+
ActiveRecord::Base.connection.execute("ALTER SEQUENCE tweets_id_seq RESTART WITH 1")
7+
8+
dracula = Monster.create(name: "Dracula", description: "Chupa sange. Hincha del rojo. Libertario. ALA")
9+
king_kong = Monster.create(name: "King Kong", description: "Gorila gigante. #VamosAVolver. BocaJrs.")
10+
nahuelito = Monster.create(name: "Nahuelito", description: "Vivo en el Nahuel Huapi. Soltero. Fanático del plancton.")
11+
hombre_lobo = Monster.create(name: "Hombre lobo", description: "Mitad lobo - mitad humano.")
12+
13+
Tweet.create(content: "Soy fanático de Walking Dead", monster: dracula)
14+
Tweet.create(content: "Se nadar espalda y mariposa desde que nací", monster: dracula)
15+
Tweet.create(content: "La mona lisa es la mona más fea", monster: king_kong)
16+
Tweet.create(content: "Soy un tipo con la sangre fría", monster: dracula)
17+
Tweet.create(content: "Me gusta el asado jugoso", monster: dracula)
18+
Tweet.create(content: "Fanático del Planeta de los Simios", monster: king_kong)
19+
Tweet.create(content: "Destapo las latas con los dientes", monster: dracula)
20+
Tweet.create(content: "El ajo en la ensalada me cae mal", monster: dracula)
21+
22+
puts "Done."

0 commit comments

Comments
 (0)