Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DB::ColumnTypeMismatchError for Int32 columns in CockroachDB #920

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions spec/avram/migrator/alter_table_statement_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe Avram::Migrator::AlterTableStatement do
ADD name text,
ADD email text,
ADD nickname text NOT NULL,
ADD age int NOT NULL DEFAULT '1',
ADD age int4 NOT NULL DEFAULT '1',
ADD num bigint NOT NULL DEFAULT '1',
ADD amount_paid decimal(10,5) NOT NULL DEFAULT '1.0',
ADD completed boolean NOT NULL DEFAULT 'false',
Expand All @@ -41,7 +41,7 @@ describe Avram::Migrator::AlterTableStatement do
ADD updated_at timestamptz,
ADD future_time timestamptz NOT NULL DEFAULT '#{Time.local.to_utc}',
ADD new_id uuid NOT NULL DEFAULT '46d9b2f0-0718-4d4c-a5a1-5af81d5b11e0',
ADD numbers int[],
ADD numbers int4[],
DROP old_column,
DROP employee_id;
SQL
Expand Down Expand Up @@ -73,7 +73,7 @@ describe Avram::Migrator::AlterTableStatement do
built.statements[0].should eq "ALTER TABLE users ALTER COLUMN id SET DATA TYPE bigint;"
built.statements[1].should eq "ALTER TABLE users ALTER COLUMN age SET DATA TYPE decimal(1,2);"
built.statements[2].should eq "ALTER TABLE users ALTER COLUMN name SET DATA TYPE citext;"
built.statements[3].should eq "ALTER TABLE users ALTER COLUMN total_score SET DATA TYPE int;"
built.statements[3].should eq "ALTER TABLE users ALTER COLUMN total_score SET DATA TYPE int4;"
end

it "can change column defaults" do
Expand Down
8 changes: 4 additions & 4 deletions spec/avram/migrator/create_table_statement_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ describe Avram::Migrator::CreateTableStatement do
built.statements.size.should eq 1
built.statements.first.should eq <<-SQL
CREATE TABLE users (
id serial PRIMARY KEY,
id serial4 PRIMARY KEY,
created_at timestamptz NOT NULL DEFAULT NOW(),
updated_at timestamptz NOT NULL DEFAULT NOW(),
name text NOT NULL,
age int NOT NULL,
age int4 NOT NULL,
completed boolean NOT NULL,
joined_at timestamptz NOT NULL,
amount_paid decimal(10,2) NOT NULL,
Expand Down Expand Up @@ -130,7 +130,7 @@ describe Avram::Migrator::CreateTableStatement do
CREATE TABLE users (
name text NOT NULL DEFAULT 'name',
email text DEFAULT 'optional',
age int NOT NULL DEFAULT '1',
age int4 NOT NULL DEFAULT '1',
num bigint NOT NULL DEFAULT '1',
amount_paid decimal NOT NULL DEFAULT '1.0',
completed boolean NOT NULL DEFAULT 'false',
Expand All @@ -157,7 +157,7 @@ describe Avram::Migrator::CreateTableStatement do
built.statements.first.should eq <<-SQL
CREATE TABLE users (
name text NOT NULL,
age int NOT NULL,
age int4 NOT NULL,
email text NOT NULL);
SQL
built.statements[1].should eq "CREATE INDEX users_name_index ON users USING btree (name);"
Expand Down
2 changes: 1 addition & 1 deletion src/avram/migrator/columns/int32_column.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Avram::Migrator::Columns
end

def column_type : String
"int"
"int4"
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Avram::Migrator::Columns::PrimaryKeys
end

def column_type : String
"serial"
"serial4"
end
end
end