Skip to content

Commit

Permalink
feat: better support for elixir releases through new ash_uuid otp_app…
Browse files Browse the repository at this point in the history
… name config; resolve #6; minor bugfixes; deps ugrade
  • Loading branch information
moissela committed Jan 24, 2024
1 parent 7804c59 commit e73a43d
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 49 deletions.
4 changes: 2 additions & 2 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# [[ $ZOONECT == "1" ]] && dotenv
# [[ $ZOONECT == "1" ]] && use flake .ops
[[ $ZOONECT == "1" ]] && [[ $ZOONECT_WORKSTATION -ne "2" ]] && dotenv
[[ $ZOONECT == "1" ]] && [[ $ZOONECT_WORKSTATION -ne "2" ]] && use flake .ops
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
/.ops/.overmind.sock
.overmind.sock

# Brew bundle
/Brewfile.lock.json

# If you run "mix test --cover", coverage assets end up here.
/cover/
/priv/cover
Expand Down
7 changes: 7 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[env]
# mise.file = [".env"]
DATABASE_URL = "postgres://postgres:[email protected]:51015/ash_uuid_test"

[tools]
erlang = "26.1.2"
elixir = "1.15.7-otp-26"
14 changes: 13 additions & 1 deletion .ops/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Db postgres port: `59001`

Setup commands:
Setup commands (with workstation@nix):

cd ash-uuid
initdb -U postgres $DATA_POSTGRES
Expand All @@ -15,6 +15,18 @@ Setup commands:
mix ash_postgres.migrate
mix test

Setup commands (with workstation@mise):

cd ash-uuid
brew bundle
mise install
mix deps.get
mix ash_postgres.drop
mix ash_postgres.generate_migrations
mix ash_postgres.create
mix ash_postgres.migrate
mix test

Morning routine commands:

overmind quit
Expand Down
12 changes: 6 additions & 6 deletions .ops/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs-unstable { inherit system overlays; };

erlangVersion = "erlang_26";
erlang = pkgs.beam.interpreters.${erlangVersion};
# erlangVersion = "erlang_26";
# erlang = pkgs.beam.interpreters.${erlangVersion};

elixirVersion = "elixir_1_15";
elixir = pkgs.beam.packages.${erlangVersion}.${elixirVersion};
# elixirVersion = "elixir_1_15";
# elixir = pkgs.beam.packages.${erlangVersion}.${elixirVersion};

rustVersion = "1.70.0";
rust = pkgs.rust-bin.stable.${rustVersion}.default;
Expand All @@ -31,8 +31,8 @@
in rec {
devShells.default = nixpkgs-unstable.legacyPackages.${system}.mkShell {
buildInputs = [
erlang
elixir
# erlang
# elixir
rust
]
++ (with pkgs; [
Expand Down
Empty file added Brewfile
Empty file.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
```elixir
def deps do
[
{:ash_uuid, "~> 0.6"},
{:ash_uuid, "~> 0.7"},
]
end
```
Expand All @@ -20,7 +20,7 @@ end

Adoption:

- add `{:ash_uuid, "~> 0.6"}`` to your `mix.exs`` project deps;
- add `{:ash_uuid, "~> 0.7"}`` to your `mix.exs`` project deps;

- add `AshUUID.PostgresExtension`` to your app Repo's installed_extensions and set AshUUID config `migration_default?: true` if Postgres-side UUIDs generation is needed;

Expand Down Expand Up @@ -50,7 +50,10 @@ end
### `config/config.exs`:

```elixir
# AshUUID: Customized defaults, not required
# AshUUID: Your otp_app name, required!
config :ash_uuid, :otp_app, :myapp

# Myapp: Customized defaults, not required
config :myapp, :ash_uuid,
version: 7, # default
encoded?: true, # default
Expand Down
2 changes: 2 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ end
if Mix.env() == :test do
config :mix_test_watch, clear: true, tasks: ["test", "credo"]

config :ash_uuid, :otp_app, :ash_uuid

config :ash_uuid, AshUUID.Test.Repo,
parameters: [plan_cache_mode: "force_custom_plan"],
pool: Ecto.Adapters.SQL.Sandbox,
Expand Down
31 changes: 30 additions & 1 deletion lib/ash_uuid/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ defmodule AshUUID.Config do
strict?: true

def get_config(opts \\ []) do
otp_app = Mix.Project.config()[:app]
otp_app =
try_getting_app_name_from_config()
|> try_getting_app_name_from_mix_project()
|> try_getting_app_name_from_mix_exs()

configs =
Application.get_env(otp_app, :ash_uuid, [])
Expand Down Expand Up @@ -40,4 +43,30 @@ defmodule AshUUID.Config do
do: raise("AshUUID config is not valid: can't use prefixed without encoded!")

defp valid?(%__MODULE__{}), do: nil

defp try_getting_app_name_from_config do
Application.get_env(:ash_uuid, :otp_app, nil)
end

defp try_getting_app_name_from_mix_project(nil) do
case Code.ensure_compiled(Mix.Project) do
{:module, Mix.Project} -> Mix.Project.config()[:app]
_ -> nil
end
end

defp try_getting_app_name_from_mix_project(app_name), do: app_name

defp try_getting_app_name_from_mix_exs(nil) do
if File.exists?("mix.exs") do
mix_file = "mix.exs" |> File.read!()
[_, name] = Regex.run(~r/[ ]+app: :([^,]+),/, to_string(mix_file))

String.to_existing_atom(name)
else
nil
end
end

defp try_getting_app_name_from_mix_exs(app_name), do: app_name
end
12 changes: 6 additions & 6 deletions lib/ash_uuid/transformers/postgres_migration_defaults.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ defmodule AshUUID.Transformers.PostgresMigrationDefaults do
version: _,
encoded?: _,
prefixed?: _,
strict?: _,
migration_default?: true
migration_default?: true,
strict?: _
]
} ->
true
Expand All @@ -40,8 +40,8 @@ defmodule AshUUID.Transformers.PostgresMigrationDefaults do
version: 4,
encoded?: _,
prefixed?: _,
strict?: _,
migration_default?: true
migration_default?: true,
strict?: _
]
} ->
{name, "fragment(\"uuid_generate_v4()\")"}
Expand All @@ -54,8 +54,8 @@ defmodule AshUUID.Transformers.PostgresMigrationDefaults do
version: 7,
encoded?: _,
prefixed?: _,
strict?: _,
migration_default?: true
migration_default?: true,
strict?: _
]
} ->
{name, "fragment(\"uuid_generate_v7()\")"}
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule AshUUID.MixProject do
use Mix.Project

@name :ash_uuid
@version "0.6.0"
@version "0.7.0"
@description "Tools for using UUID based id with Ash"
@source_url "https://github.com/zoonect-oss/ash_uuid"

Expand Down
Loading

0 comments on commit e73a43d

Please sign in to comment.