diff --git a/crates/formatter/src/attr_order.rs b/crates/formatter/src/attr_order.rs index e12c2a2..a64c843 100644 --- a/crates/formatter/src/attr_order.rs +++ b/crates/formatter/src/attr_order.rs @@ -103,20 +103,31 @@ pub(crate) fn canonical_order(words: &[W]) -> Option> { if object != "function" && object != "procedure" { return None; } - // The name: never an attribute starter, however it is spelled. - let (i, _) = word_at(words, pos)?; - pos = i + 1; - // Qualified-name continuations: `.` then another name part. - loop { - let mut j = pos; - while matches!(words.get(j), Some(W::Trivia)) { - j += 1; - } - if !matches!(words.get(j), Some(W::Dot)) { - break; + // The name: never an attribute starter, however it is spelled. In + // the lowerer's element view, `f()` parses as a call *expression*, + // so name and parens can arrive as one opaque node. + let mut j = pos; + while matches!(words.get(j), Some(W::Trivia)) { + j += 1; + } + match words.get(j)? { + W::Other => pos = j + 1, + W::Word(_) => { + pos = j + 1; + // Qualified-name continuations: `.` then another name part. + loop { + let mut j = pos; + while matches!(words.get(j), Some(W::Trivia)) { + j += 1; + } + if !matches!(words.get(j), Some(W::Dot)) { + break; + } + let (k, _) = word_at(words, j + 1)?; + pos = k + 1; + } } - let (k, _) = word_at(words, j + 1)?; - pos = k + 1; + _ => return None, } // Tail scan: segment starts at each attribute keyword at paren diff --git a/crates/formatter/tests/bodies.rs b/crates/formatter/tests/bodies.rs index 9804597..447d1a5 100644 --- a/crates/formatter/tests/bodies.rs +++ b/crates/formatter/tests/bodies.rs @@ -28,9 +28,10 @@ fn language_sql_body_formats_and_anchors() { #[test] fn language_before_as_also_detected() { let out = format("CREATE FUNCTION two() RETURNS int AS $$SELECT 2$$ LANGUAGE sql;"); + // The body formats as SQL, and the clause reorders canonically. assert_eq!( out, - "create function two()\nreturns int\nas $$\n\tselect 2\n$$\nlanguage sql;\n" + "create function two()\nreturns int\nlanguage sql\nas $$\n\tselect 2\n$$;\n" ); } diff --git a/crates/formatter/tests/rules.rs b/crates/formatter/tests/rules.rs index d8544e8..d7bdc30 100644 --- a/crates/formatter/tests/rules.rs +++ b/crates/formatter/tests/rules.rs @@ -145,3 +145,14 @@ fn crlf_input_normalizes_to_lf() { assert!(!out.contains('\r')); assert_eq!(format(&out), out); } + +#[test] +fn function_attributes_reorder_even_with_empty_parens() { + // `f()` parses as a call expression (name and parens in one node); + // the canonical attribute order must still apply. + let out = format("create function f() returns trigger as 'x' language plpgsql;"); + assert_eq!( + out, + "create function f()\nreturns trigger\nlanguage plpgsql\nas 'x';\n" + ); +} diff --git a/crates/formatter/tests/snapshots/snapshots__migrations__000238_notification_preferences.up.snap b/crates/formatter/tests/snapshots/snapshots__migrations__000238_notification_preferences.up.snap index f3760d6..a8e9a8a 100644 --- a/crates/formatter/tests/snapshots/snapshots__migrations__000238_notification_preferences.up.snap +++ b/crates/formatter/tests/snapshots/snapshots__migrations__000238_notification_preferences.up.snap @@ -30,6 +30,7 @@ alter type notification_message_status add value if not exists 'inhibited'; -- Function to prevent enqueuing notifications unnecessarily. create or replace function inhibit_enqueue_if_disabled() returns trigger +language plpgsql as $$ begin -- Fail the insertion if the user has disabled this notification. @@ -45,8 +46,7 @@ as $$ end if; return NEW; end; -$$ -language plpgsql; +$$; -- Trigger to execute above function on insertion. create trigger inhibit_enqueue_if_disabled diff --git a/crates/formatter/tests/snapshots/snapshots__migrations__000241_delete_user_roles.up.snap b/crates/formatter/tests/snapshots/snapshots__migrations__000241_delete_user_roles.up.snap index 5da0af5..9720657 100644 --- a/crates/formatter/tests/snapshots/snapshots__migrations__000241_delete_user_roles.up.snap +++ b/crates/formatter/tests/snapshots/snapshots__migrations__000241_delete_user_roles.up.snap @@ -1,6 +1,5 @@ --- source: crates/formatter/tests/snapshots.rs -assertion_line: 30 expression: formatted --- -- When a custom role is deleted, we need to remove the assigned role @@ -9,6 +8,7 @@ expression: formatted -- done with caution. create or replace function remove_organization_member_role() returns trigger +language plpgsql as $$ begin -- Delete the role from all organization members that have it. @@ -27,8 +27,7 @@ as $$ end if; return OLD; end; -$$ -language plpgsql; +$$; -- Attach the function to deleting the custom role create trigger remove_organization_member_custom_role diff --git a/crates/formatter/tests/snapshots/snapshots__migrations__000245_notifications_dedupe.up.snap b/crates/formatter/tests/snapshots/snapshots__migrations__000245_notifications_dedupe.up.snap index 5bc1b5f..a0311f5 100644 --- a/crates/formatter/tests/snapshots/snapshots__migrations__000245_notifications_dedupe.up.snap +++ b/crates/formatter/tests/snapshots/snapshots__migrations__000245_notifications_dedupe.up.snap @@ -16,6 +16,7 @@ create unique index on notification_messages (dedupe_hash); -- This could have been a unique index, but we cannot immutably create an index on a timestamp with a timezone. create or replace function compute_notification_message_dedupe_hash() returns trigger +language plpgsql as $$ begin new.dedupe_hash := md5( @@ -31,8 +32,7 @@ as $$ ); return NEW; end; -$$ -language plpgsql; +$$; comment on function compute_notification_message_dedupe_hash is 'Computes a unique hash which will be used to prevent duplicate messages from being enqueued on the same day'; create trigger update_notification_message_dedupe_hash diff --git a/crates/formatter/tests/snapshots/snapshots__migrations__000283_user_status_changes.up.snap b/crates/formatter/tests/snapshots/snapshots__migrations__000283_user_status_changes.up.snap index 5800169..9716c37 100644 --- a/crates/formatter/tests/snapshots/snapshots__migrations__000283_user_status_changes.up.snap +++ b/crates/formatter/tests/snapshots/snapshots__migrations__000283_user_status_changes.up.snap @@ -1,6 +1,5 @@ --- source: crates/formatter/tests/snapshots.rs -assertion_line: 30 expression: formatted --- create table user_status_changes ( @@ -37,6 +36,7 @@ where deleted; create or replace function record_user_status_change() returns trigger +language plpgsql as $$ begin if TG_OP = 'INSERT' or OLD.status is distinct from NEW.status then @@ -49,8 +49,7 @@ as $$ end if; return NEW; end; -$$ -language plpgsql; +$$; create trigger user_status_change_trigger after insert or update on users diff --git a/crates/formatter/tests/snapshots/snapshots__migrations__000284_allow_disabling_notification_templates_by_default.down.snap b/crates/formatter/tests/snapshots/snapshots__migrations__000284_allow_disabling_notification_templates_by_default.down.snap index 8c6509f..7e9a747 100644 --- a/crates/formatter/tests/snapshots/snapshots__migrations__000284_allow_disabling_notification_templates_by_default.down.snap +++ b/crates/formatter/tests/snapshots/snapshots__migrations__000284_allow_disabling_notification_templates_by_default.down.snap @@ -6,6 +6,7 @@ alter table notification_templates drop column enabled_by_default; create or replace function inhibit_enqueue_if_disabled() returns trigger +language plpgsql as $$ begin -- Fail the insertion if the user has disabled this notification. @@ -21,5 +22,4 @@ as $$ end if; return NEW; end; -$$ -language plpgsql; +$$; diff --git a/crates/formatter/tests/snapshots/snapshots__migrations__000284_allow_disabling_notification_templates_by_default.up.snap b/crates/formatter/tests/snapshots/snapshots__migrations__000284_allow_disabling_notification_templates_by_default.up.snap index 7aa9b8a..88186bf 100644 --- a/crates/formatter/tests/snapshots/snapshots__migrations__000284_allow_disabling_notification_templates_by_default.up.snap +++ b/crates/formatter/tests/snapshots/snapshots__migrations__000284_allow_disabling_notification_templates_by_default.up.snap @@ -7,6 +7,7 @@ alter table notification_templates create or replace function inhibit_enqueue_if_disabled() returns trigger +language plpgsql as $$ begin -- Fail the insertion if one of the following: @@ -37,5 +38,4 @@ as $$ end if; return NEW; end; -$$ -language plpgsql; +$$; diff --git a/crates/formatter/tests/snapshots/snapshots__migrations__000296_organization_soft_delete.up.snap b/crates/formatter/tests/snapshots/snapshots__migrations__000296_organization_soft_delete.up.snap index be326e1..b6310c6 100644 --- a/crates/formatter/tests/snapshots/snapshots__migrations__000296_organization_soft_delete.up.snap +++ b/crates/formatter/tests/snapshots/snapshots__migrations__000296_organization_soft_delete.up.snap @@ -1,6 +1,5 @@ --- source: crates/formatter/tests/snapshots.rs -assertion_line: 30 expression: formatted --- alter table organizations add column deleted boolean default false not null; @@ -17,6 +16,7 @@ alter table only organizations drop constraint if exists organizations_name; create function protect_deleting_organizations() returns trigger +language plpgsql as $$ declare workspace_count int; @@ -77,8 +77,7 @@ as $$ end if; return NEW; end; -$$ -language plpgsql; +$$; -- Trigger to protect organizations from being soft deleted with existing resources create trigger protect_deleting_organizations diff --git a/crates/formatter/tests/snapshots/snapshots__migrations__000310_update_protect_deleting_organization_function.down.snap b/crates/formatter/tests/snapshots/snapshots__migrations__000310_update_protect_deleting_organization_function.down.snap index 61da28b..3e8d5b4 100644 --- a/crates/formatter/tests/snapshots/snapshots__migrations__000310_update_protect_deleting_organization_function.down.snap +++ b/crates/formatter/tests/snapshots/snapshots__migrations__000310_update_protect_deleting_organization_function.down.snap @@ -1,6 +1,5 @@ --- source: crates/formatter/tests/snapshots.rs -assertion_line: 30 expression: formatted --- -- Drop trigger that uses this function @@ -9,6 +8,7 @@ drop trigger if exists protect_deleting_organizations on organizations; -- Revert the function to its original implementation create or replace function protect_deleting_organizations() returns trigger +language plpgsql as $$ declare workspace_count int; @@ -69,8 +69,7 @@ as $$ end if; return NEW; end; -$$ -language plpgsql; +$$; -- Re-create trigger that uses this function create trigger protect_deleting_organizations diff --git a/crates/formatter/tests/snapshots/snapshots__migrations__000310_update_protect_deleting_organization_function.up.snap b/crates/formatter/tests/snapshots/snapshots__migrations__000310_update_protect_deleting_organization_function.up.snap index 21a3fab..477ae10 100644 --- a/crates/formatter/tests/snapshots/snapshots__migrations__000310_update_protect_deleting_organization_function.up.snap +++ b/crates/formatter/tests/snapshots/snapshots__migrations__000310_update_protect_deleting_organization_function.up.snap @@ -1,6 +1,5 @@ --- source: crates/formatter/tests/snapshots.rs -assertion_line: 30 expression: formatted --- drop trigger if exists protect_deleting_organizations on organizations; @@ -8,6 +7,7 @@ drop trigger if exists protect_deleting_organizations on organizations; -- Replace the function with the new implementation create or replace function protect_deleting_organizations() returns trigger +language plpgsql as $$ declare workspace_count int; @@ -92,8 +92,7 @@ as $$ end if; return NEW; end; -$$ -language plpgsql; +$$; -- Trigger to protect organizations from being soft deleted with existing resources create trigger protect_deleting_organizations diff --git a/crates/formatter/tests/snapshots/snapshots__migrations__000318_update_protect_deleting_orgs_to_filter_deleted_users.down.snap b/crates/formatter/tests/snapshots/snapshots__migrations__000318_update_protect_deleting_orgs_to_filter_deleted_users.down.snap index 0cb12ce..477ae10 100644 --- a/crates/formatter/tests/snapshots/snapshots__migrations__000318_update_protect_deleting_orgs_to_filter_deleted_users.down.snap +++ b/crates/formatter/tests/snapshots/snapshots__migrations__000318_update_protect_deleting_orgs_to_filter_deleted_users.down.snap @@ -7,6 +7,7 @@ drop trigger if exists protect_deleting_organizations on organizations; -- Replace the function with the new implementation create or replace function protect_deleting_organizations() returns trigger +language plpgsql as $$ declare workspace_count int; @@ -91,8 +92,7 @@ as $$ end if; return NEW; end; -$$ -language plpgsql; +$$; -- Trigger to protect organizations from being soft deleted with existing resources create trigger protect_deleting_organizations diff --git a/crates/formatter/tests/snapshots/snapshots__migrations__000318_update_protect_deleting_orgs_to_filter_deleted_users.up.snap b/crates/formatter/tests/snapshots/snapshots__migrations__000318_update_protect_deleting_orgs_to_filter_deleted_users.up.snap index cc40084..ba40736 100644 --- a/crates/formatter/tests/snapshots/snapshots__migrations__000318_update_protect_deleting_orgs_to_filter_deleted_users.up.snap +++ b/crates/formatter/tests/snapshots/snapshots__migrations__000318_update_protect_deleting_orgs_to_filter_deleted_users.up.snap @@ -7,6 +7,7 @@ drop trigger if exists protect_deleting_organizations on organizations; -- Replace the function with the new implementation create or replace function protect_deleting_organizations() returns trigger +language plpgsql as $$ declare workspace_count int; @@ -93,8 +94,7 @@ as $$ end if; return NEW; end; -$$ -language plpgsql; +$$; -- Trigger to protect organizations from being soft deleted with existing resources create trigger protect_deleting_organizations diff --git a/crates/formatter/tests/snapshots/snapshots__migrations__000332_workspace_agent_name_unique_trigger.up.snap b/crates/formatter/tests/snapshots/snapshots__migrations__000332_workspace_agent_name_unique_trigger.up.snap index 044529a..0c84145 100644 --- a/crates/formatter/tests/snapshots/snapshots__migrations__000332_workspace_agent_name_unique_trigger.up.snap +++ b/crates/formatter/tests/snapshots/snapshots__migrations__000332_workspace_agent_name_unique_trigger.up.snap @@ -4,6 +4,7 @@ expression: formatted --- create or replace function check_workspace_agent_name_unique() returns trigger +language plpgsql as $$ declare workspace_build_id uuid; @@ -45,8 +46,7 @@ as $$ end if; return NEW; end; -$$ -language plpgsql; +$$; create trigger workspace_agent_name_unique_trigger before insert or update of name, diff --git a/crates/formatter/tests/snapshots/snapshots__migrations__000338_use_deleted_boolean_for_subagents.down.snap b/crates/formatter/tests/snapshots/snapshots__migrations__000338_use_deleted_boolean_for_subagents.down.snap index 71fd0f5..40224f3 100644 --- a/crates/formatter/tests/snapshots/snapshots__migrations__000338_use_deleted_boolean_for_subagents.down.snap +++ b/crates/formatter/tests/snapshots/snapshots__migrations__000338_use_deleted_boolean_for_subagents.down.snap @@ -67,6 +67,7 @@ drop function IF exists check_workspace_agent_name_unique(); create or replace function check_workspace_agent_name_unique() returns trigger +language plpgsql as $$ declare workspace_build_id uuid; @@ -108,8 +109,7 @@ as $$ end if; return NEW; end; -$$ -language plpgsql; +$$; create trigger workspace_agent_name_unique_trigger before insert or update of name, diff --git a/crates/formatter/tests/snapshots/snapshots__migrations__000338_use_deleted_boolean_for_subagents.up.snap b/crates/formatter/tests/snapshots/snapshots__migrations__000338_use_deleted_boolean_for_subagents.up.snap index 8cc60d9..7c1d629 100644 --- a/crates/formatter/tests/snapshots/snapshots__migrations__000338_use_deleted_boolean_for_subagents.up.snap +++ b/crates/formatter/tests/snapshots/snapshots__migrations__000338_use_deleted_boolean_for_subagents.up.snap @@ -12,6 +12,7 @@ drop function IF exists check_workspace_agent_name_unique(); create or replace function check_workspace_agent_name_unique() returns trigger +language plpgsql as $$ declare workspace_build_id uuid; @@ -56,8 +57,7 @@ as $$ end if; return NEW; end; -$$ -language plpgsql; +$$; create trigger workspace_agent_name_unique_trigger before insert or update of name, diff --git a/crates/formatter/tests/snapshots/snapshots__migrations__000362_aggregate_usage_events.up.snap b/crates/formatter/tests/snapshots/snapshots__migrations__000362_aggregate_usage_events.up.snap index 92ca681..a202d82 100644 --- a/crates/formatter/tests/snapshots/snapshots__migrations__000362_aggregate_usage_events.up.snap +++ b/crates/formatter/tests/snapshots/snapshots__migrations__000362_aggregate_usage_events.up.snap @@ -15,6 +15,7 @@ comment on column usage_events_daily.day is 'The date of the summed usage events -- Function to handle usage event aggregation create or replace function aggregate_usage_event() returns trigger +language plpgsql as $$ begin -- Check for supported event types and throw error for unknown types @@ -45,8 +46,7 @@ as $$ end; return NEW; end; -$$ -language plpgsql; +$$; -- Create trigger to automatically aggregate usage events create trigger trigger_aggregate_usage_event diff --git a/crates/formatter/tests/snapshots/snapshots__migrations__000408_create_org_member_system_roles.up.snap b/crates/formatter/tests/snapshots/snapshots__migrations__000408_create_org_member_system_roles.up.snap index d4b8a71..b50e1a1 100644 --- a/crates/formatter/tests/snapshots/snapshots__migrations__000408_create_org_member_system_roles.up.snap +++ b/crates/formatter/tests/snapshots/snapshots__migrations__000408_create_org_member_system_roles.up.snap @@ -55,6 +55,7 @@ where -- placeholder org-member system role for it. create or replace function insert_org_member_system_role() returns trigger +language plpgsql as $$ begin insert into custom_roles ( @@ -84,8 +85,7 @@ as $$ ); return NEW; end; -$$ -language plpgsql; +$$; create trigger trigger_insert_org_member_system_role after insert on organizations diff --git a/crates/formatter/tests/snapshots/snapshots__migrations__000443_three_options_for_allowed_workspace_sharing.down.snap b/crates/formatter/tests/snapshots/snapshots__migrations__000443_three_options_for_allowed_workspace_sharing.down.snap index 16a6ece..324314f 100644 --- a/crates/formatter/tests/snapshots/snapshots__migrations__000443_three_options_for_allowed_workspace_sharing.down.snap +++ b/crates/formatter/tests/snapshots/snapshots__migrations__000443_three_options_for_allowed_workspace_sharing.down.snap @@ -23,6 +23,7 @@ drop function IF exists insert_organization_system_roles; create or replace function insert_org_member_system_role() returns trigger +language plpgsql as $$ begin insert into custom_roles ( @@ -52,8 +53,7 @@ as $$ ); return NEW; end; -$$ -language plpgsql; +$$; create trigger trigger_insert_org_member_system_role after insert on organizations diff --git a/crates/formatter/tests/snapshots/snapshots__migrations__000443_three_options_for_allowed_workspace_sharing.up.snap b/crates/formatter/tests/snapshots/snapshots__migrations__000443_three_options_for_allowed_workspace_sharing.up.snap index 76eb0cc..173cd37 100644 --- a/crates/formatter/tests/snapshots/snapshots__migrations__000443_three_options_for_allowed_workspace_sharing.up.snap +++ b/crates/formatter/tests/snapshots/snapshots__migrations__000443_three_options_for_allowed_workspace_sharing.up.snap @@ -63,6 +63,7 @@ drop function IF exists insert_org_member_system_role; create or replace function insert_organization_system_roles() returns trigger +language plpgsql as $$ begin insert into custom_roles ( @@ -104,8 +105,7 @@ as $$ ); return NEW; end; -$$ -language plpgsql; +$$; create trigger trigger_insert_organization_system_roles after insert on organizations diff --git a/crates/formatter/tests/snapshots/snapshots__migrations__000444_usage_events_ai_seats.down.snap b/crates/formatter/tests/snapshots/snapshots__migrations__000444_usage_events_ai_seats.down.snap index 237f611..679926c 100644 --- a/crates/formatter/tests/snapshots/snapshots__migrations__000444_usage_events_ai_seats.down.snap +++ b/crates/formatter/tests/snapshots/snapshots__migrations__000444_usage_events_ai_seats.down.snap @@ -18,6 +18,7 @@ alter table usage_events -- Restore the original aggregate function without hb_ai_seats_v1 support. create or replace function aggregate_usage_event() returns trigger +language plpgsql as $$ begin if NEW.event_type not in ('dc_managed_agents_v1') then @@ -44,5 +45,4 @@ as $$ end; return NEW; end; -$$ -language plpgsql; +$$; diff --git a/crates/formatter/tests/snapshots/snapshots__migrations__000444_usage_events_ai_seats.up.snap b/crates/formatter/tests/snapshots/snapshots__migrations__000444_usage_events_ai_seats.up.snap index aea2bf7..f2fbc78 100644 --- a/crates/formatter/tests/snapshots/snapshots__migrations__000444_usage_events_ai_seats.up.snap +++ b/crates/formatter/tests/snapshots/snapshots__migrations__000444_usage_events_ai_seats.up.snap @@ -19,6 +19,7 @@ create index idx_usage_events_ai_seats -- Heartbeat events replace the previous value for the same time period. create or replace function aggregate_usage_event() returns trigger +language plpgsql as $$ begin -- Check for supported event types and throw error for unknown types. @@ -56,5 +57,4 @@ as $$ end; return NEW; end; -$$ -language plpgsql; +$$; diff --git a/crates/formatter/tests/snapshots/snapshots__migrations__000510_cleanup_chats_mcp_server_ids_on_delete.up.snap b/crates/formatter/tests/snapshots/snapshots__migrations__000510_cleanup_chats_mcp_server_ids_on_delete.up.snap index 5883729..a9e817f 100644 --- a/crates/formatter/tests/snapshots/snapshots__migrations__000510_cleanup_chats_mcp_server_ids_on_delete.up.snap +++ b/crates/formatter/tests/snapshots/snapshots__migrations__000510_cleanup_chats_mcp_server_ids_on_delete.up.snap @@ -33,6 +33,7 @@ where create or replace function remove_mcp_server_config_id_from_chats() returns trigger +language plpgsql as $$ begin update chats @@ -40,8 +41,7 @@ as $$ where OLD.id = any(mcp_server_ids); return OLD; end; -$$ -language plpgsql; +$$; create trigger remove_chat_mcp_server_config_id before delete on mcp_server_configs diff --git a/crates/formatter/tests/snapshots/snapshots__migrations__000519_chatd_core_state_machine.up.snap b/crates/formatter/tests/snapshots/snapshots__migrations__000519_chatd_core_state_machine.up.snap index 10fdcaf..eb5e5bf 100644 --- a/crates/formatter/tests/snapshots/snapshots__migrations__000519_chatd_core_state_machine.up.snap +++ b/crates/formatter/tests/snapshots/snapshots__migrations__000519_chatd_core_state_machine.up.snap @@ -127,6 +127,7 @@ create index if not exists chat_heartbeats_heartbeat_at_idx -- in a CTE on chats and then inserts messages). create function set_chat_message_revision_before() returns trigger +language plpgsql as $$ declare chat_snapshot_version bigint; @@ -155,8 +156,7 @@ as $$ new.revision = chat_snapshot_version; return NEW; end; -$$ -language plpgsql; +$$; -- AFTER STATEMENT trigger functions. Use the transition tables to -- update chats.history_version / generation_attempt once per chat per @@ -172,6 +172,7 @@ language plpgsql; -- had previously been bumped. create function update_chat_history_after_message_insert() returns trigger +language plpgsql as $$ begin update chats c @@ -185,11 +186,11 @@ as $$ ); return null; end; -$$ -language plpgsql; +$$; create function update_chat_history_after_message_update() returns trigger +language plpgsql as $$ begin update chats c @@ -208,8 +209,7 @@ as $$ ); return null; end; -$$ -language plpgsql; +$$; create trigger trigger_set_chat_message_revision_on_insert before insert on chat_messages @@ -234,6 +234,7 @@ create trigger trigger_update_chat_history_after_message_update -- 13. Queue version trigger function. create function bump_chat_queue_version_on_queued_message_change() returns trigger +language plpgsql as $$ declare changed_chat_id uuid; @@ -249,8 +250,7 @@ as $$ end if; return NEW; end; -$$ -language plpgsql; +$$; create trigger trigger_bump_chat_queue_version_on_queued_message_insert after insert on chat_queued_messages @@ -273,6 +273,7 @@ create trigger trigger_bump_chat_queue_version_on_queued_message_delete -- 14. Retry state trigger function. create function sync_chat_retry_state() returns trigger +language plpgsql as $$ begin if OLD.retry_state_version is distinct from NEW.retry_state_version then @@ -286,8 +287,7 @@ as $$ end if; return NEW; end; -$$ -language plpgsql; +$$; create trigger trigger_sync_chat_retry_state before update of retry_state, diff --git a/crates/formatter/tests/snapshots/snapshots__migrations__000545_chat_search_schema.down.snap b/crates/formatter/tests/snapshots/snapshots__migrations__000545_chat_search_schema.down.snap index a0cecd2..7942c20 100644 --- a/crates/formatter/tests/snapshots/snapshots__migrations__000545_chat_search_schema.down.snap +++ b/crates/formatter/tests/snapshots/snapshots__migrations__000545_chat_search_schema.down.snap @@ -5,6 +5,7 @@ expression: formatted -- Restore the original trigger bodies from 000519. create or replace function set_chat_message_revision_before() returns trigger +language plpgsql as $$ declare chat_snapshot_version bigint; @@ -33,11 +34,11 @@ as $$ new.revision = chat_snapshot_version; return NEW; end; -$$ -language plpgsql; +$$; create or replace function update_chat_history_after_message_update() returns trigger +language plpgsql as $$ begin update chats c @@ -56,8 +57,7 @@ as $$ ); return null; end; -$$ -language plpgsql; +$$; drop index if exists idx_chat_diff_statuses_pr_title_fts; diff --git a/crates/formatter/tests/snapshots/snapshots__migrations__000545_chat_search_schema.up.snap b/crates/formatter/tests/snapshots/snapshots__migrations__000545_chat_search_schema.up.snap index 8866731..f21361c 100644 --- a/crates/formatter/tests/snapshots/snapshots__migrations__000545_chat_search_schema.up.snap +++ b/crates/formatter/tests/snapshots/snapshots__migrations__000545_chat_search_schema.up.snap @@ -89,6 +89,7 @@ comment on index idx_chats_title_fts is 'Used for full text search. Defined over create or replace function set_chat_message_revision_before() returns trigger +language plpgsql as $$ declare chat_snapshot_version bigint; @@ -120,13 +121,13 @@ as $$ new.revision = chat_snapshot_version; return NEW; end; -$$ -language plpgsql; +$$; comment on function set_chat_message_revision_before is 'Component of chatd. Updates chat_snapshot_version when any fields of chat_messages change. Excludes changes to search_tsv as it is not relevant to chatd''s processing loop.'; create or replace function update_chat_history_after_message_update() returns trigger +language plpgsql as $$ begin update chats c @@ -146,7 +147,6 @@ as $$ ); return null; end; -$$ -language plpgsql; +$$; comment on function update_chat_history_after_message_update is 'Component of chatd. Updates history_version and generation_attempt on chats when chat_messages is updated. Excludes changes to search_tsv.'; diff --git a/docs/.gitignore b/docs/.gitignore new file mode 100644 index 0000000..ddce69b --- /dev/null +++ b/docs/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +dist/ +.astro/ diff --git a/docs/astro.config.mjs b/docs/astro.config.mjs new file mode 100644 index 0000000..28813de --- /dev/null +++ b/docs/astro.config.mjs @@ -0,0 +1,6 @@ +// @ts-check +import { defineConfig } from "astro/config"; + +export default defineConfig({ + site: "https://squill.tree.ht", +}); diff --git a/docs/package.json b/docs/package.json new file mode 100644 index 0000000..e1cf76f --- /dev/null +++ b/docs/package.json @@ -0,0 +1,14 @@ +{ + "name": "squill-docs", + "type": "module", + "version": "0.0.1", + "private": true, + "scripts": { + "dev": "astro dev", + "build": "astro build", + "preview": "astro preview" + }, + "dependencies": { + "astro": "^5" + } +}