-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for subclasses in defaults allowed types #1052
base: master
Are you sure you want to change the base?
Conversation
@Bobronium Thanks for this. Do you know the status of |
Actually, I'm just defining custom function for now ✨ Example migrationfrom piccolo.apps.migrations.auto import MigrationManager
from piccolo.table import Table
ID = "2024-07-13T21:20:34:913115"
VERSION = "1.13.1"
DESCRIPTION = "ADD UUIDv7"
UUID_GENERATE_V7_SQL = """\
-- Function to generate new v7 UUIDs.
-- Would be better off using https://github.com/fboulnois/pg_uuidv7, but can't on RDS.
-- Or, once the UUIDv7 spec is finalized, it will probably make it into the 'uuid-ossp' extension
-- and a custom function will no longer be necessary.
create or replace function uuid_generate_v7()
returns uuid
as $$
declare
unix_ts_ms bytea;
uuid_bytes bytea;
begin
unix_ts_ms = substring(int8send(floor(extract(epoch from clock_timestamp()) * 1000)::bigint) from 3);
uuid_bytes = uuid_send(gen_random_uuid());
uuid_bytes = overlay(uuid_bytes placing unix_ts_ms from 1 for 6);
uuid_bytes = set_byte(uuid_bytes, 6, (b'0111' || get_byte(uuid_bytes, 6)::bit(4))::bit(8)::int);
return encode(uuid_bytes, 'hex')::uuid;
end
$$
language plpgsql
volatile;""" # noqa: E501
class RawTable(Table):
pass
async def add_uuid_v7() -> None:
await RawTable.raw(UUID_GENERATE_V7_SQL)
async def forwards() -> None:
manager = MigrationManager(migration_id=ID, app_name="app", description=DESCRIPTION)
manager.add_raw(add_uuid_v7) |
Will it be merged? Maybe we can add a UUID7 class with this change so no need for custom class creation |
These changes allow for extension of existing Default types, for instance, introducing UUID7 would now be possible just like this: