-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5654b9b
commit f211ccc
Showing
2 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"ash_functions_version": 4, | ||
"ash_functions_version": 5, | ||
"installed": [ | ||
"ash-functions" | ||
] | ||
|
60 changes: 60 additions & 0 deletions
60
priv/test_repo/migrations/20250123123641_update_extensions_1.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
defmodule AshArchival.TestRepo.Migrations.UpdateExtensions1 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("ALTER FUNCTION ash_raise_error(jsonb) STABLE;") | ||
execute("ALTER FUNCTION ash_raise_error(jsonb, ANYCOMPATIBLE) STABLE") | ||
|
||
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 | ||
SET search_path = '' | ||
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 | ||
SET search_path = '' | ||
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("ALTER FUNCTION ash_raise_error(jsonb) VOLATILE;") | ||
execute("ALTER FUNCTION ash_raise_error(jsonb, ANYCOMPATIBLE) VOLATILE") | ||
end | ||
end |