Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/dbv1/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ddl/functions/handle_challenge_disbursements.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
create or replace function handle_challenge_disbursement() returns trigger as $$
declare
reward_manager_tx reward_manager_txs%ROWTYPE;
existing_notification integer;
existing_notification bigint;
reward_code_exists boolean;
begin

Expand Down Expand Up @@ -67,7 +67,7 @@ end $$;
create or replace function handle_sol_reward_disbursement() returns trigger as $$
declare
resolved_user_id integer;
existing_notification integer;
existing_notification bigint;
reward_code_exists boolean;
begin
select users.user_id
Expand Down
2 changes: 1 addition & 1 deletion ddl/functions/handle_user_challenges.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
create or replace function handle_on_user_challenge() returns trigger as $$
declare
cooldown_days integer;
existing_notification integer;
existing_notification bigint;
listen_streak_value integer;
begin
if (new.is_complete = true) then
Expand Down
43 changes: 43 additions & 0 deletions ddl/migrations/0233_notification_id_bigint.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
-- notification_id_seq exhausted its signed 32-bit range in production. Widen
-- both the owning column and the sequence so notification inserts can resume.
--
-- ALTER COLUMN integer -> bigint rewrites notification and requires an
-- ACCESS EXCLUSIVE lock. Fail quickly if the lock is not immediately
-- available so an unattended deploy cannot leave requests queued behind this
-- migration. Production should run this while notification readers and writers
-- are quiesced, then retry the migration.

BEGIN;

SET LOCAL lock_timeout = '5s';
SET LOCAL statement_timeout = '0';

DO $$
BEGIN
IF EXISTS (
SELECT 1
FROM pg_attribute
WHERE attrelid = 'public.notification'::regclass
AND attname = 'id'
AND atttypid = 'integer'::regtype
AND NOT attisdropped
) THEN
LOCK TABLE public.notification IN ACCESS EXCLUSIVE MODE;

ALTER TABLE public.notification
ALTER COLUMN id TYPE bigint;
END IF;

IF EXISTS (
SELECT 1
FROM pg_sequences
WHERE schemaname = 'public'
AND sequencename = 'notification_id_seq'
AND data_type = 'integer'::regtype
) THEN
ALTER SEQUENCE public.notification_id_seq AS bigint;
END IF;
END
$$;

COMMIT;
11 changes: 5 additions & 6 deletions sql/01_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2141,7 +2141,7 @@ CREATE FUNCTION public.handle_challenge_disbursement() RETURNS trigger
AS $$
declare
reward_manager_tx reward_manager_txs%ROWTYPE;
existing_notification integer;
existing_notification bigint;
reward_code_exists boolean;
begin

Expand Down Expand Up @@ -3235,7 +3235,7 @@ CREATE FUNCTION public.handle_on_user_challenge() RETURNS trigger
AS $$
declare
cooldown_days integer;
existing_notification integer;
existing_notification bigint;
listen_streak_value integer;
begin
if (new.is_complete = true) then
Expand Down Expand Up @@ -4376,7 +4376,7 @@ CREATE FUNCTION public.handle_sol_reward_disbursement() RETURNS trigger
AS $$
declare
resolved_user_id integer;
existing_notification integer;
existing_notification bigint;
reward_code_exists boolean;
begin
select users.user_id
Expand Down Expand Up @@ -8653,7 +8653,7 @@ CREATE TABLE public.muted_users (
--

CREATE TABLE public.notification (
id integer NOT NULL,
id bigint NOT NULL,
specifier character varying NOT NULL,
group_id character varying NOT NULL,
type character varying NOT NULL,
Expand Down Expand Up @@ -8682,7 +8682,7 @@ CREATE TABLE public.notification_campaign_push_open (
--

CREATE SEQUENCE public.notification_id_seq
AS integer
AS bigint
START WITH 1
INCREMENT BY 1
NO MINVALUE
Expand Down Expand Up @@ -14991,4 +14991,3 @@ ALTER TABLE ONLY public.users
-- PostgreSQL database dump complete
--


Loading