kamaroly

kamaroly

I just attempted to change all the to uuid_primary_key to uuid_v7_primary_key and now it is throwing the following error. I followed the documentation and ensured to have "uuid-ossp" in my Repo’s installed_extensions/0.

What could I be missing?

22:31:50.622 [info] create table users
** (Postgrex.Error) ERROR 42883 (undefined_function) function uuid_generate_v7() does not exist

    hint: No function matches the given name and argument types. You might need to add explicit type casts.
    (ecto_sql 3.12.1) lib/ecto/adapters/sql.ex:1096: Ecto.Adapters.SQL.raise_sql_call_error/1

Showing Posts 1 to 5

sezaru

sezaru

If I would guess, I think you are missing "ash-functions" in the installed_extensions/0 no?

kamaroly

kamaroly OP

It’s there in my repo. Here it is:

defmodule Hr.Repo do
  use AshPostgres.Repo,
    otp_app: :hr

  def installed_extensions do
    # Add extensions here, and the
    # migration generator will install them.
    ["ash-functions", "uuid-ossp", "citext"]
  end

  def min_pg_version do
    # Adjust this according to your postgres version
    %Version{major: 16, minor: 0, patch: 0}
  end

  @doc """
  Used by migrations --tenants to list all tenants,
  create related schemas and migrates
  """
  def all_tenants do
    for tenant <- Hr.Accounts.get_organisations!() do
      tenant.domain
    end
  end
end
sezaru

sezaru

Did you generate the migration for it?

For example, here is mine adding that function:

defmodule Core.Repo.Migrations.InstallAshFunctionsExtension420240925162123 do
  @moduledoc """
  Installs any extensions that are mentioned in the repo's `installed_extensions/0` callback

  This file was autogenerated with `mix ash_postgres.generate_migrations`
  """

  use Ecto.Migration

  def up do
    execute("""
    CREATE OR REPLACE FUNCTION uuid_generate_v7()
    RETURNS UUID
    AS $$
    DECLARE
      timestamp    TIMESTAMPTZ;
      microseconds INT;
    BEGIN
      timestamp    = clock_timestamp();
      microseconds = (cast(extract(microseconds FROM timestamp)::INT - (floor(extract(milliseconds FROM timestamp))::INT * 1000) AS DOUBLE PRECISION) * 4.096)::INT;

      RETURN encode(
        set_byte(
          set_byte(
            overlay(uuid_send(gen_random_uuid()) placing substring(int8send(floor(extract(epoch FROM timestamp) * 1000)::BIGINT) FROM 3) FROM 1 FOR 6
          ),
          6, (b'0111' || (microseconds >> 8)::bit(4))::bit(8)::int
        ),
        7, microseconds::bit(8)::int
      ),
      'hex')::UUID;
    END
    $$
    LANGUAGE PLPGSQL
    VOLATILE;
    """)

    execute("""
    CREATE OR REPLACE FUNCTION timestamp_from_uuid_v7(_uuid uuid)
    RETURNS TIMESTAMP WITHOUT TIME ZONE
    AS $$
      SELECT to_timestamp(('x0000' || substr(_uuid::TEXT, 1, 8) || substr(_uuid::TEXT, 10, 4))::BIT(64)::BIGINT::NUMERIC / 1000);
    $$
    LANGUAGE SQL
    IMMUTABLE PARALLEL SAFE STRICT;
    """)
  end

  def down do
    # Uncomment this if you actually want to uninstall the extensions
    # when this migration is rolled back:
    execute("DROP FUNCTION IF EXISTS uuid_generate_v7(), timestamp_from_uuid_v7(uuid)")
  end
end
kamaroly

kamaroly OP

Uh, I can see. For me running mix ash_postgres.generate_migrations isn’t generating this Migration. I will copy and use yours.

kamaroly

kamaroly OP

I had to delete hr/priv/resource_snapshots/repo/extensions.json and the extensions migration, then run mix ash_postgres.generate_migrations to have the uuid_generate_v7() added to the migrations.

Thanks.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

xinz
Hello everyone! :waving_hand: I’d like to share JSONSchex, a JSON Schema Draft 2020-12 library for Elixir focused on correctness, repeat...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews