Skip to content

Commit 130d227

Browse files
Add rake database tasks:
* `rake databases:recreate` * `rake databases:migrate_all` * `rake databases:cycle_database`
1 parent 8ca0a4b commit 130d227

5 files changed

+27
-8
lines changed

db/migrate/20140823052830_create_comments.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class CreateComments < ActiveRecord::Migration
1+
class CreateComments < ActiveRecord::Migration[5.0]
22
def change
33
create_table :comments do |t|
44
t.string :author

db/migrate/20151015160035_set_default_for_author_and_text.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class SetDefaultForAuthorAndText < ActiveRecord::Migration
1+
class SetDefaultForAuthorAndText < ActiveRecord::Migration[5.0]
22
def up
33
change_column_default(:comments, :author, "")
44
change_column_default(:comments, :text, "")

db/migrate/20151015160334_change_author_and_text_to_not_null.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class ChangeAuthorAndTextToNotNull < ActiveRecord::Migration
1+
class ChangeAuthorAndTextToNotNull < ActiveRecord::Migration[5.0]
22
def change
33
change_column_null(:comments, :author, false, "")
44
change_column_null(:comments, :text, false, "")

db/schema.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
1717

18-
create_table "comments", force: :cascade do |t|
19-
t.string "author", default: "", null: false
20-
t.text "text", default: "", null: false
21-
t.datetime "created_at", null: false
22-
t.datetime "updated_at", null: false
18+
create_table "comments", id: :serial, force: :cascade do |t|
19+
t.string "author", default: "", null: false
20+
t.text "text", default: "", null: false
21+
t.datetime "created_at", null: false
22+
t.datetime "updated_at", null: false
2323
end
2424

2525
end

lib/tasks/databases.rake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace :databases do
2+
task :recreate do
3+
puts Rainbow("\nRecreate Rails Databases:\n").blueviolet.bright.underline
4+
sh "rake db:drop"
5+
sh "rake db:create"
6+
end
7+
8+
task :migrate_all do
9+
puts Rainbow("\nRun Rails Migrations:\n").blueviolet.bright.underline
10+
sh "rake db:migrate"
11+
sh "rake db:migrate ENV=test"
12+
end
13+
14+
task :cycle_database do
15+
sh "rails db:environment:set RAILS_ENV=development"
16+
Rake::Task["databases:recreate"].invoke
17+
Rake::Task["databases:migrate_all"].invoke
18+
end
19+
end

0 commit comments

Comments
 (0)