diff --git a/lib/ash_authentication/token_resource/transformer.ex b/lib/ash_authentication/token_resource/transformer.ex index 51b3e57..e9c5b3f 100644 --- a/lib/ash_authentication/token_resource/transformer.ex +++ b/lib/ash_authentication/token_resource/transformer.ex @@ -63,7 +63,7 @@ defmodule AshAuthentication.TokenResource.Transformer do writable?: true ), {:ok, dsl_state} <- - maybe_build_attribute(dsl_state, :created_at, :utc_datetime_usec, + maybe_build_attribute(dsl_state, :inserted_at, :utc_datetime_usec, allow_nil?: false, private?: true, default: &DateTime.utc_now/0 @@ -73,6 +73,7 @@ defmodule AshAuthentication.TokenResource.Transformer do allow_nil?: false, private?: true, default: &DateTime.utc_now/0, + match_other_defaults?: true, update_default: &DateTime.utc_now/0 ), :ok <- validate_extra_data_field(dsl_state), diff --git a/priv/repo/migrations/20230921214515_rename_created_at_to_inserted_at.exs b/priv/repo/migrations/20230921214515_rename_created_at_to_inserted_at.exs new file mode 100644 index 0000000..d52c1b8 --- /dev/null +++ b/priv/repo/migrations/20230921214515_rename_created_at_to_inserted_at.exs @@ -0,0 +1,25 @@ +defmodule Example.Repo.Migrations.RenameCreatedAtToInsertedAt do + @moduledoc """ + Updates resources based on their most recent snapshots. + + This file was autogenerated with `mix ash_postgres.generate_migrations` + """ + + use Ecto.Migration + + def up do + rename table(:user_with_token_required), :created_at, to: :inserted_at + + rename table(:user), :created_at, to: :inserted_at + + rename table(:tokens), :created_at, to: :inserted_at + end + + def down do + rename table(:tokens), :inserted_at, to: :created_at + + rename table(:user), :inserted_at, to: :created_at + + rename table(:user_with_token_required), :inserted_at, to: :created_at + end +end \ No newline at end of file diff --git a/priv/resource_snapshots/repo/tokens/20230921214515.json b/priv/resource_snapshots/repo/tokens/20230921214515.json new file mode 100644 index 0000000..4141674 --- /dev/null +++ b/priv/resource_snapshots/repo/tokens/20230921214515.json @@ -0,0 +1,89 @@ +{ + "attributes": [ + { + "allow_nil?": false, + "default": "fragment(\"now()\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "updated_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": false, + "default": "fragment(\"now()\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "inserted_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "extra_data", + "type": "map" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "purpose", + "type": "text" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "expires_at", + "type": "utc_datetime" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "subject", + "type": "text" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": true, + "references": null, + "size": null, + "source": "jti", + "type": "text" + } + ], + "base_filter": null, + "check_constraints": [], + "custom_indexes": [], + "custom_statements": [], + "has_create_action": true, + "hash": "25131200B3413B973EF0B7756EBA3FE5C2A7BB5DFE4570E821B040E67D56C858", + "identities": [], + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "repo": "Elixir.Example.Repo", + "schema": null, + "table": "tokens" +} \ No newline at end of file diff --git a/priv/resource_snapshots/repo/user/20230921214515.json b/priv/resource_snapshots/repo/user/20230921214515.json new file mode 100644 index 0000000..134bdb5 --- /dev/null +++ b/priv/resource_snapshots/repo/user/20230921214515.json @@ -0,0 +1,108 @@ +{ + "attributes": [ + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "confirmed_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": false, + "default": "fragment(\"uuid_generate_v4()\")", + "generated?": false, + "primary_key?": true, + "references": null, + "size": null, + "source": "id", + "type": "uuid" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "username", + "type": "citext" + }, + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "extra_stuff", + "type": "text" + }, + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "not_accepted_extra_stuff", + "type": "text" + }, + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "hashed_password", + "type": "text" + }, + { + "allow_nil?": false, + "default": "fragment(\"now()\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "inserted_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": false, + "default": "fragment(\"now()\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "updated_at", + "type": "utc_datetime_usec" + } + ], + "base_filter": null, + "check_constraints": [], + "custom_indexes": [], + "custom_statements": [], + "has_create_action": true, + "hash": "E3D96D702989FA5E11CDA575DDD6A4EEADCCCFEBB1C1A0D319E75699C0F92172", + "identities": [ + { + "base_filter": null, + "index_name": "user_username_index", + "keys": [ + "username" + ], + "name": "username" + } + ], + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "repo": "Elixir.Example.Repo", + "schema": null, + "table": "user" +} \ No newline at end of file diff --git a/priv/resource_snapshots/repo/user_with_token_required/20230921214515.json b/priv/resource_snapshots/repo/user_with_token_required/20230921214515.json new file mode 100644 index 0000000..91ae09c --- /dev/null +++ b/priv/resource_snapshots/repo/user_with_token_required/20230921214515.json @@ -0,0 +1,78 @@ +{ + "attributes": [ + { + "allow_nil?": false, + "default": "fragment(\"uuid_generate_v4()\")", + "generated?": false, + "primary_key?": true, + "references": null, + "size": null, + "source": "id", + "type": "uuid" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "email", + "type": "citext" + }, + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "hashed_password", + "type": "text" + }, + { + "allow_nil?": false, + "default": "fragment(\"now()\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "inserted_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": false, + "default": "fragment(\"now()\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "updated_at", + "type": "utc_datetime_usec" + } + ], + "base_filter": null, + "check_constraints": [], + "custom_indexes": [], + "custom_statements": [], + "has_create_action": true, + "hash": "FDF27DC116615A2B66AE8B12AD9152E5F3AB41926FA406C4656F92CB4C1167B0", + "identities": [ + { + "base_filter": null, + "index_name": "user_with_token_required_email_index", + "keys": [ + "email" + ], + "name": "email" + } + ], + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "repo": "Elixir.Example.Repo", + "schema": null, + "table": "user_with_token_required" +} \ No newline at end of file diff --git a/test/ash_authentication/add_ons/confirmation/actions_test.exs b/test/ash_authentication/add_ons/confirmation/actions_test.exs index 3ee5b42..45d3832 100644 --- a/test/ash_authentication/add_ons/confirmation/actions_test.exs +++ b/test/ash_authentication/add_ons/confirmation/actions_test.exs @@ -72,7 +72,7 @@ defmodule AshAuthentication.AddOn.Confirmation.ActionsTest do query = from(t in Example.Token, where: t.purpose == "confirm", - order_by: [desc: t.created_at], + order_by: [desc: t.inserted_at], limit: 1 ) diff --git a/test/support/example/user.ex b/test/support/example/user.ex index 9907859..e177a07 100644 --- a/test/support/example/user.ex +++ b/test/support/example/user.ex @@ -15,7 +15,7 @@ defmodule Example.User do id: Ecto.UUID.t(), username: String.t(), hashed_password: String.t(), - created_at: DateTime.t(), + inserted_at: DateTime.t(), updated_at: DateTime.t() } @@ -27,7 +27,7 @@ defmodule Example.User do attribute :not_accepted_extra_stuff, :string attribute :hashed_password, :string, allow_nil?: true, sensitive?: true, private?: true - create_timestamp :created_at + create_timestamp :inserted_at update_timestamp :updated_at end diff --git a/test/support/example/user_with_token_required.ex b/test/support/example/user_with_token_required.ex index e4cd6ad..b3636e3 100644 --- a/test/support/example/user_with_token_required.ex +++ b/test/support/example/user_with_token_required.ex @@ -7,7 +7,7 @@ defmodule Example.UserWithTokenRequired do id: Ecto.UUID.t(), email: String.t(), hashed_password: String.t(), - created_at: DateTime.t(), + inserted_at: DateTime.t(), updated_at: DateTime.t() } @@ -15,7 +15,7 @@ defmodule Example.UserWithTokenRequired do uuid_primary_key :id, writable?: true attribute :email, :ci_string, allow_nil?: false attribute :hashed_password, :string, allow_nil?: true, sensitive?: true, private?: true - create_timestamp :created_at + create_timestamp :inserted_at update_timestamp :updated_at end