-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathusing_migrations.rb
More file actions
50 lines (38 loc) · 1.12 KB
/
using_migrations.rb
File metadata and controls
50 lines (38 loc) · 1.12 KB
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
# Active UUID features a convenience #uuid method, which may be used to create
# a binary column in database migration. Since it involves monkey patching,
# "activeid/all" must be loaded.
ENV["DB"] ||= "sqlite3"
require "bundler/setup"
Bundler.require :development
# Note "activeid/all", which registers new column definitions!
require "activeid/all"
require_relative "../spec/support/0_logger"
require_relative "../spec/support/1_db_connection"
#### SCHEMA ####
ActiveRecord::Schema.define do
create_table :authors, id: false, force: true do |t|
t.uuid :id, primary_key: true
t.string :name
t.timestamps
end
end
#### PROOF ####
SolidAssert.enable_assertions
id_column = ActiveRecord::Base.connection.columns("authors")[0]
assert id_column.name == "id"
case ENV["DB"]
when "sqlite3"
assert id_column.sql_type == "binary(16)"
when "mysql"
assert id_column.sql_type == "varbinary(16)"
when "postgresql"
assert id_column.sql_type == "uuid"
end
#### PROVE THAT ASSERTIONS WERE WORKING ####
begin
assert 1 == 2
rescue SolidAssert::AssertionFailedError
puts "All OK."
else
raise "Assertions do not work!"
end