aboutsummaryrefslogtreecommitdiffstats
path: root/spec/db
diff options
context:
space:
mode:
Diffstat (limited to 'spec/db')
-rw-r--r--spec/db/schema_spec.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/db/schema_spec.rb b/spec/db/schema_spec.rb
new file mode 100644
index 000000000..8c5492cd7
--- /dev/null
+++ b/spec/db/schema_spec.rb
@@ -0,0 +1,26 @@
+RSpec.describe ActiveRecord::Schema do
+ it "uses type `bigint` for primary and foreign keys" do
+# grep -e 'create_table.*id: :bigserial' db/schema.rb | grep -v 'id: :bigserial'
+# grep -e 'create_table.+id: :bigserial' db/schema.rb | grep -v 'id: :bigserial'
+# grep -e 't\.integer *"\w*_id"' db/schema.rb | grep -v -e 'limit: 8'
+# grep -e 't\.integer +"\w+_id"' db/schema.rb | grep -v -e 'limit: 8'
+
+ non_bigint_primary_keys = []
+ non_bigint_foreign_keys = []
+
+ File.open('db/schema.rb', 'r') do |f|
+ non_bigint_primary_keys = f
+ .grep(/create_table /)
+ .grep_v(/id: :bigserial/)
+
+ f.rewind
+
+ non_bigint_foreign_keys = f
+ .grep(/t\.integer +"\w+_id"/)
+ .grep_v(/limit: 8/)
+ end
+
+ expect(non_bigint_primary_keys).to be_empty
+ expect(non_bigint_foreign_keys).to be_empty
+ end
+end