-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
67 lines (52 loc) · 1.72 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require "bundler/gem_tasks"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
namespace :db do
task :with_settings do
require "active_record"
unless ENV["DATABASE_URL"]
require "dotenv"
Dotenv.load
end
end
task c: :with_settings do
exec "psql #{ENV.fetch('DATABASE_URL')}"
end
task drop: :with_settings do
`dropdb #{ENV.fetch("DATABASE_NAME")}`
end
task create: :with_settings do
`createdb #{ENV.fetch("DATABASE_NAME")}`
end
task migrate: :with_settings do
ActiveRecord::Base.establish_connection(ENV.fetch('DATABASE_URL'))
ActiveRecord::Schema.define do
create_table :posts, force: true do |t|
# Implicit ID
t.string :title, null: false
t.text :body, null: false
# TODO: Test default on this
t.string :tags, array: true, null: false
t.datetime :created_at, null: false
t.datetime :updated_at, null: false
end
create_table :all_types, force: :true do |t|
# Implicit ID
[:string, :text, :integer, :bigint, :float, :decimal, :numeric, :datetime, :time, :date, :binary, :boolean].each do |type|
t.send(type, "#{type}_nullable".to_sym, null: true)
t.send(type, "#{type}_not_nullable".to_sym, null: false)
t.send(type, "#{type}_array_nullable".to_sym, null: true, array: true)
t.send(type, "#{type}_array_not_nullable".to_sym, null: false, array: true)
end
t.integer :fake_enum_nullable, null: true
t.integer :fake_enum_not_nullable, null: false
end
end
puts "Migrated"
end
task setup: :with_settings do
Rake::Task['db:create'].invoke
Rake::Task['db:migrate'].invoke
end
end