From 71c0877d5654cde2f2cf5c66530adbd7a1273f13 Mon Sep 17 00:00:00 2001 From: WolfDan <5377526+WolfDan@users.noreply.github.com> Date: Mon, 12 Apr 2021 08:58:06 -0500 Subject: [PATCH 1/2] primary autoincrement key as bigserial --- lib/migration_generator/operation.ex | 2 +- test/migration_generator_test.exs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/migration_generator/operation.ex b/lib/migration_generator/operation.ex index 84a5a911..d310a1f7 100644 --- a/lib/migration_generator/operation.ex +++ b/lib/migration_generator/operation.ex @@ -178,7 +178,7 @@ defmodule AshPostgres.MigrationGenerator.Operation do def up(%{attribute: %{type: :integer, default: "nil", generated?: true} = attribute}) do [ "add #{inspect(attribute.name)}", - ":serial", + ":bigserial", maybe_add_null(attribute.allow_nil?), maybe_add_primary_key(attribute.primary_key?) ] diff --git a/test/migration_generator_test.exs b/test/migration_generator_test.exs index 16f1291c..2a7d8cd5 100644 --- a/test/migration_generator_test.exs +++ b/test/migration_generator_test.exs @@ -411,11 +411,11 @@ defmodule AshPostgres.MigrationGeneratorTest do :ok end - test "when an integer is generated and default nil, it is a serial" do + test "when an integer is generated and default nil, it is a bigserial" do assert [file] = Path.wildcard("test_migration_path/**/*_migrate_resources*.exs") assert File.read!(file) =~ - ~S[add :id, :serial, null: false, primary_key: true] + ~S[add :id, :bigserial, null: false, primary_key: true] assert File.read!(file) =~ ~S[add :views, :integer] From ce70a236f6735d6fc5310816a5622a5e1c9cd4e5 Mon Sep 17 00:00:00 2001 From: WolfDan <5377526+WolfDan@users.noreply.github.com> Date: Mon, 12 Apr 2021 12:24:36 -0500 Subject: [PATCH 2/2] references to integer keys shouls be :bigint --- lib/migration_generator/operation.ex | 29 ++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/migration_generator/operation.ex b/lib/migration_generator/operation.ex index d310a1f7..a4d115d6 100644 --- a/lib/migration_generator/operation.ex +++ b/lib/migration_generator/operation.ex @@ -39,6 +39,9 @@ defmodule AshPostgres.MigrationGenerator.Operation do end def on_update(_), do: nil + + def integer_to_bigint(:integer), do: ":bigint" + def integer_to_bigint(type), do: inspect(type) end defmodule CreateTable do @@ -68,7 +71,7 @@ defmodule AshPostgres.MigrationGenerator.Operation do "add #{inspect(attribute.name)}", "references(:#{table}", [ - "type: #{inspect(attribute.type)}", + "type: #{integer_to_bigint(attribute.type)}", "column: #{inspect(destination_field)}", "with: [#{source_attribute}: :#{destination_attribute}]", "name: #{inspect(reference.name)}", @@ -98,7 +101,7 @@ defmodule AshPostgres.MigrationGenerator.Operation do "add #{inspect(attribute.name)}", "references(:#{table}", [ - "type: #{inspect(attribute.type)}", + "type: #{integer_to_bigint(attribute.type)}", "column: #{inspect(destination_field)}", "prefix: \"public\"", "name: #{inspect(reference.name)}", @@ -140,7 +143,7 @@ defmodule AshPostgres.MigrationGenerator.Operation do "add #{inspect(attribute.name)}", "references(:#{table}", [ - "type: #{inspect(attribute.type)}", + "type: #{integer_to_bigint(attribute.type)}", "column: #{inspect(destination_field)}", "name: #{inspect(reference.name)}", on_delete(reference), @@ -162,7 +165,7 @@ defmodule AshPostgres.MigrationGenerator.Operation do "add #{inspect(attribute.name)}", "references(:#{table}", [ - "type: #{inspect(attribute.type)}", + "type: #{integer_to_bigint(attribute.type)}", "column: #{inspect(destination_field)}", "name: #{inspect(reference.name)}", on_delete(reference), @@ -269,7 +272,9 @@ defmodule AshPostgres.MigrationGenerator.Operation do } = reference }) do join([ - "references(:#{table}, type: #{inspect(type)}, column: #{inspect(destination_field)}", + "references(:#{table}, type: #{integer_to_bigint(type)}, column: #{ + inspect(destination_field) + }", "name: #{inspect(reference.name)}", on_delete(reference), on_update(reference), @@ -287,9 +292,9 @@ defmodule AshPostgres.MigrationGenerator.Operation do } = reference }) do join([ - "references(:#{table}, type: #{inspect(type)}, column: #{inspect(destination_field)}, with: [#{ - source_attribute - }: :#{destination_attribute}]", + "references(:#{table}, type: #{integer_to_bigint(type)}, column: #{ + inspect(destination_field) + }, with: [#{source_attribute}: :#{destination_attribute}]", "name: #{inspect(reference.name)}", on_delete(reference), on_update(reference), @@ -309,7 +314,9 @@ defmodule AshPostgres.MigrationGenerator.Operation do } ) do join([ - "references(:#{table}, type: #{inspect(type)}, column: #{inspect(destination_field)}, prefix: \"public\"", + "references(:#{table}, type: #{integer_to_bigint(type)}, column: #{ + inspect(destination_field) + }, prefix: \"public\"", "name: #{inspect(reference.name)}", on_delete(reference), on_update(reference), @@ -329,7 +336,9 @@ defmodule AshPostgres.MigrationGenerator.Operation do } ) do join([ - "references(:#{table}, type: #{inspect(type)}, column: #{inspect(destination_field)}", + "references(:#{table}, type: #{integer_to_bigint(type)}, column: #{ + inspect(destination_field) + }", "name: #{inspect(reference.name)}", on_delete(reference), on_update(reference),