-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvement: mark ash_raise_error as STABLE
- Loading branch information
1 parent
8e59757
commit 1d0437a
Showing
5 changed files
with
145 additions
and
4 deletions.
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
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", | ||
"uuid-ossp", | ||
|
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", | ||
"uuid-ossp", | ||
|
60 changes: 60 additions & 0 deletions
60
priv/test_no_sandbox_repo/migrations/20250113205301_migrate_resources_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 AshPostgres.TestNoSandboxRepo.Migrations.MigrateResourcesExtensions1 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 |
60 changes: 60 additions & 0 deletions
60
priv/test_repo/migrations/20250113205259_migrate_resources_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 AshPostgres.TestRepo.Migrations.MigrateResourcesExtensions1 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 |