Skip to content

Commit

Permalink
Enforce null: false on columns consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
shioyama committed Apr 11, 2018
1 parent 966c4f8 commit 724462e
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ class CreateStringTranslations < <%= activerecord_migration_class %>

def change
create_table :mobility_string_translations do |t|
t.string :locale
t.string :key
t.string :locale, null: false
t.string :key, null: false
t.string :value
t.integer :translatable_id
t.string :translatable_type
t.timestamps
t.integer :translatable_id, null: false
t.string :translatable_type, null: false
t.timestamps null: false
end
add_index :mobility_string_translations, [:translatable_id, :translatable_type, :locale, :key], unique: true, name: :index_mobility_string_translations_on_keys
add_index :mobility_string_translations, [:translatable_id, :translatable_type, :key], name: :index_mobility_string_translations_on_translatable_attribute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ class CreateTextTranslations < <%= activerecord_migration_class %>

def change
create_table :mobility_text_translations do |t|
t.string :locale
t.string :key
t.string :locale, null: false
t.string :key, null: false
t.text :value
t.integer :translatable_id
t.string :translatable_type
t.timestamps
t.integer :translatable_id, null: false
t.string :translatable_type, null: false
t.timestamps null: false
end
add_index :mobility_text_translations, [:translatable_id, :translatable_type, :locale, :key], unique: true, name: :index_mobility_text_translations_on_keys
add_index :mobility_text_translations, [:translatable_id, :translatable_type, :key], name: :index_mobility_text_translations_on_translatable_attribute
Expand Down
28 changes: 14 additions & 14 deletions spec/active_record/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,41 @@ class << self
def up
create_table "posts" do |t|
t.boolean :published
t.timestamps
t.timestamps null: false
end

create_table "articles" do |t|
t.string :slug
t.boolean :published
t.timestamps
t.timestamps null: false
end

create_table "article_translations" do |t|
t.string :locale
t.integer :article_id
t.string :title
t.text :content
t.timestamps
t.timestamps null: false
end

create_table "multitable_posts" do |t|
t.string :slug
t.boolean :published
t.timestamps
t.timestamps null: false
end

create_table "multitable_post_translations" do |t|
t.string :locale
t.integer :multitable_post_id
t.string :title
t.timestamps
t.timestamps null: false
end

create_table "multitable_post_foo_translations" do |t|
t.string :locale
t.integer :multitable_post_id
t.string :foo
t.timestamps
t.timestamps null: false
end

create_table "mobility_string_translations" do |t|
Expand All @@ -53,7 +53,7 @@ def up
t.string :value, null: false
t.integer :translatable_id, null: false
t.string :translatable_type, null: false
t.timestamps
t.timestamps null: false
end
add_index :mobility_string_translations, [:translatable_id, :translatable_type, :locale, :key], unique: true, name: :index_mobility_string_translations_on_keys
add_index :mobility_string_translations, [:translatable_id, :translatable_type, :key], name: :index_mobility_string_translations_on_translatable_attribute
Expand All @@ -65,7 +65,7 @@ def up
t.text :value, null: false
t.integer :translatable_id, null: false
t.string :translatable_type, null: false
t.timestamps
t.timestamps null: false
end
add_index :mobility_text_translations, [:translatable_id, :translatable_type, :locale, :key], unique: true, name: :index_mobility_text_translations_on_keys
add_index :mobility_text_translations, [:translatable_id, :translatable_type, :key], name: :index_mobility_text_translations_on_translatable_attribute
Expand All @@ -80,35 +80,35 @@ def up
t.text :author_pt_br
t.text :author_ru
t.boolean :published
t.timestamps
t.timestamps null: false
end

create_table "serialized_posts" do |t|
t.text :my_title_i18n
t.text :my_content_i18n
t.boolean :published
t.timestamps
t.timestamps null: false
end

if ENV['DB'] == 'postgres'
create_table "jsonb_posts" do |t|
t.jsonb :my_title_i18n, default: {}
t.jsonb :my_content_i18n, default: {}
t.boolean :published
t.timestamps
t.timestamps null: false
end

create_table "json_posts" do |t|
t.json :my_title_i18n, default: {}
t.json :my_content_i18n, default: {}
t.boolean :published
t.timestamps
t.timestamps null: false
end

create_table "container_posts" do |t|
t.jsonb :translations, default: {}
t.boolean :published
t.timestamps
t.timestamps null: false
end

execute "CREATE EXTENSION IF NOT EXISTS hstore"
Expand All @@ -117,7 +117,7 @@ def up
t.hstore :my_title_i18n, default: ''
t.hstore :my_content_i18n, default: ''
t.boolean :published
t.timestamps
t.timestamps null: false
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/generators/rails/mobility/translations_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@
before do
connection.create_table :post_translations do |t|
t.string :locale
t.integer :post_id
t.timestamps
t.integer :post_id, null: false
t.timestamps null: false
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/mobility/backends/active_record/container_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
m = ActiveRecord::Migration.new
m.verbose = false
m.create_table :json_container_posts do |t|
t.json :json_translations, default: {}
t.json :json_translations, default: {}, null: false
t.boolean :published
t.timestamps
t.timestamps null: false
end
end
before(:each) do
Expand All @@ -94,7 +94,7 @@
m.create_table :string_column_posts do |t|
t.string :foo
t.boolean :published
t.timestamps
t.timestamps null: false
end
end
after(:all) do
Expand Down
88 changes: 44 additions & 44 deletions spec/sequel/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def migrate(*)
DB.create_table? :post_metadatas do
primary_key :id
String :metadata
Integer :post_id
Integer :post_id, allow_null: false
DateTime :created_at, allow_null: false
DateTime :updated_at, allow_null: false
end
Expand All @@ -31,8 +31,8 @@ def migrate(*)

DB.create_table? :article_translations do
primary_key :id
Integer :article_id
String :locale
Integer :article_id, allow_null: false
String :locale, allow_null: false
String :title
String :content, size: 65535
DateTime :created_at, allow_null: false
Expand All @@ -48,45 +48,45 @@ def migrate(*)

DB.create_table? :multitable_post_translations do
primary_key :id
Integer :multitable_post_id
String :locale
Integer :multitable_post_id, allow_null: false
String :locale, allow_null: false
String :title
DateTime :created_at, allow_null: false
DateTime :updated_at, allow_null: false
DateTime :created_at, allow_null: false
DateTime :updated_at, allow_null: false
end


DB.create_table? :multitable_post_foo_translations do
primary_key :id
Integer :multitable_post_id
String :locale
Integer :multitable_post_id, allow_null: false
String :locale, allow_null: false
String :foo
DateTime :created_at, allow_null: false
DateTime :updated_at, allow_null: false
DateTime :created_at, allow_null: false
DateTime :updated_at, allow_null: false
end

DB.create_table? :mobility_text_translations do
primary_key :id
String :locale, null: false
String :key, null: false
String :value, null: false, size: 65535
Integer :translatable_id, null: false
String :translatable_type, null: false
DateTime :created_at, allow_null: false
DateTime :updated_at, allow_null: false
String :locale, allow_null: false
String :key
String :value
Integer :translatable_id, allow_null: false
String :translatable_type, allow_null: false
DateTime :created_at, allow_null: false
DateTime :updated_at, allow_null: false
index [:translatable_id, :translatable_type, :locale, :key], unique: true, name: :index_mobility_text_translations_on_keys
index [:translatable_id, :translatable_type, :key], name: :index_mobility_text_translations_on_translatable_attribute
end

DB.create_table? :mobility_string_translations do
primary_key :id
String :locale, null: false
String :key, null: false
String :value, null: false
Integer :translatable_id, null: false
String :translatable_type, null: false
DateTime :created_at, allow_null: false
DateTime :updated_at, allow_null: false
String :locale, allow_null: false
String :key, allow_null: false
String :value
Integer :translatable_id, allow_null: false
String :translatable_type, allow_null: false
DateTime :created_at, allow_null: false
DateTime :updated_at, allow_null: false
index [:translatable_id, :translatable_type, :locale, :key], unique: true, name: :index_mobility_string_translations_on_keys
index [:translatable_id, :translatable_type, :key], name: :index_mobility_string_translations_on_translatable_attribute
index [:translatable_type, :key, :value, :locale], name: :index_mobility_string_translations_on_query_keys
Expand All @@ -109,48 +109,48 @@ def migrate(*)

DB.create_table? :serialized_posts do
primary_key :id
String :my_title_i18n, size: 65535
String :my_content_i18n, size: 65535
String :my_title_i18n, size: 65535
String :my_content_i18n, size: 65535
TrueClass :published
DateTime :created_at, allow_null: false
DateTime :updated_at, allow_null: false
DateTime :created_at, allow_null: false
DateTime :updated_at, allow_null: false
end

if ENV['DB'] == 'postgres'
DB.create_table? :jsonb_posts do
primary_key :id
jsonb :my_title_i18n, default: '{}'
jsonb :my_content_i18n, default: '{}'
jsonb :my_title_i18n, default: '{}', allow_null: false
jsonb :my_content_i18n, default: '{}', allow_null: false
TrueClass :published
DateTime :created_at, allow_null: false
DateTime :updated_at, allow_null: false
DateTime :created_at, allow_null: false
DateTime :updated_at, allow_null: false
end

DB.create_table? :json_posts do
primary_key :id
json :my_title_i18n, default: '{}'
json :my_content_i18n, default: '{}'
json :my_title_i18n, default: '{}', allow_null: false
json :my_content_i18n, default: '{}', allow_null: false
TrueClass :published
DateTime :created_at, allow_null: false
DateTime :updated_at, allow_null: false
DateTime :created_at, allow_null: false
DateTime :updated_at, allow_null: false
end

DB.create_table? :container_posts do
primary_key :id
jsonb :translations, default: '{}'
jsonb :translations, default: '{}', allow_null: false
TrueClass :published
DateTime :created_at, allow_null: false
DateTime :updated_at, allow_null: false
DateTime :created_at, allow_null: false
DateTime :updated_at, allow_null: false
end

DB.run "CREATE EXTENSION IF NOT EXISTS hstore"
DB.create_table? :hstore_posts do
primary_key :id
hstore :my_title_i18n, default: ''
hstore :my_content_i18n, default: ''
hstore :my_title_i18n, default: '', allow_null: false
hstore :my_content_i18n, default: '', allow_null: false
TrueClass :published
DateTime :created_at, allow_null: false
DateTime :updated_at, allow_null: false
DateTime :created_at, allow_null: false
DateTime :updated_at, allow_null: false
end
end
end
Expand Down

0 comments on commit 724462e

Please sign in to comment.