Something went wrong. Try again.
Event Sourcing Framework on top of Microsoft Orleans and PostgreSQL
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189-- Orleans Reminders table - https://learn.microsoft.com/dotnet/orleans/grains/timers-and-remindersCREATE TABLE OrleansRemindersTable( ServiceId varchar(150) NOT NULL, GrainId varchar(150) NOT NULL, ReminderName varchar(150) NOT NULL, StartTime timestamptz(3) NOT NULL, Period bigint NOT NULL, GrainHash integer NOT NULL, Version integer NOT NULL,
CONSTRAINT PK_RemindersTable_ServiceId_GrainId_ReminderName PRIMARY KEY(ServiceId, GrainId, ReminderName));
CREATE FUNCTION upsert_reminder_row( ServiceIdArg OrleansRemindersTable.ServiceId%TYPE, GrainIdArg OrleansRemindersTable.GrainId%TYPE, ReminderNameArg OrleansRemindersTable.ReminderName%TYPE, StartTimeArg OrleansRemindersTable.StartTime%TYPE, PeriodArg OrleansRemindersTable.Period%TYPE, GrainHashArg OrleansRemindersTable.GrainHash%TYPE ) RETURNS TABLE(version integer) AS$func$DECLARE VersionVar int := 0;BEGIN
INSERT INTO OrleansRemindersTable ( ServiceId, GrainId, ReminderName, StartTime, Period, GrainHash, Version ) SELECT ServiceIdArg, GrainIdArg, ReminderNameArg, StartTimeArg, PeriodArg, GrainHashArg, 0 ON CONFLICT (ServiceId, GrainId, ReminderName) DO UPDATE SET StartTime = excluded.StartTime, Period = excluded.Period, GrainHash = excluded.GrainHash, Version = OrleansRemindersTable.Version + 1 RETURNING OrleansRemindersTable.Version INTO STRICT VersionVar;
RETURN QUERY SELECT VersionVar AS versionr;
END$func$ LANGUAGE plpgsql;
INSERT INTO OrleansQuery(QueryKey, QueryText)VALUES( 'UpsertReminderRowKey',' SELECT * FROM upsert_reminder_row( @ServiceId, @GrainId, @ReminderName, @StartTime, @Period, @GrainHash );');
INSERT INTO OrleansQuery(QueryKey, QueryText)VALUES( 'ReadReminderRowsKey',' SELECT GrainId, ReminderName, StartTime, Period, Version FROM OrleansRemindersTable WHERE ServiceId = @ServiceId AND @ServiceId IS NOT NULL AND GrainId = @GrainId AND @GrainId IS NOT NULL;');
INSERT INTO OrleansQuery(QueryKey, QueryText)VALUES( 'ReadReminderRowKey',' SELECT GrainId, ReminderName, StartTime, Period, Version FROM OrleansRemindersTable WHERE ServiceId = @ServiceId AND @ServiceId IS NOT NULL AND GrainId = @GrainId AND @GrainId IS NOT NULL AND ReminderName = @ReminderName AND @ReminderName IS NOT NULL;');
INSERT INTO OrleansQuery(QueryKey, QueryText)VALUES( 'ReadRangeRows1Key',' SELECT GrainId, ReminderName, StartTime, Period, Version FROM OrleansRemindersTable WHERE ServiceId = @ServiceId AND @ServiceId IS NOT NULL AND GrainHash > @BeginHash AND @BeginHash IS NOT NULL AND GrainHash <= @EndHash AND @EndHash IS NOT NULL;');
INSERT INTO OrleansQuery(QueryKey, QueryText)VALUES( 'ReadRangeRows2Key',' SELECT GrainId, ReminderName, StartTime, Period, Version FROM OrleansRemindersTable WHERE ServiceId = @ServiceId AND @ServiceId IS NOT NULL AND ((GrainHash > @BeginHash AND @BeginHash IS NOT NULL) OR (GrainHash <= @EndHash AND @EndHash IS NOT NULL));');
CREATE FUNCTION delete_reminder_row( ServiceIdArg OrleansRemindersTable.ServiceId%TYPE, GrainIdArg OrleansRemindersTable.GrainId%TYPE, ReminderNameArg OrleansRemindersTable.ReminderName%TYPE, VersionArg OrleansRemindersTable.Version%TYPE) RETURNS TABLE(row_count integer) AS$func$DECLARE RowCountVar int := 0;BEGIN
DELETE FROM OrleansRemindersTable WHERE ServiceId = ServiceIdArg AND ServiceIdArg IS NOT NULL AND GrainId = GrainIdArg AND GrainIdArg IS NOT NULL AND ReminderName = ReminderNameArg AND ReminderNameArg IS NOT NULL AND Version = VersionArg AND VersionArg IS NOT NULL;
GET DIAGNOSTICS RowCountVar = ROW_COUNT;
RETURN QUERY SELECT RowCountVar;
END$func$ LANGUAGE plpgsql;
INSERT INTO OrleansQuery(QueryKey, QueryText)VALUES( 'DeleteReminderRowKey',' SELECT * FROM delete_reminder_row( @ServiceId, @GrainId, @ReminderName, @Version );');
INSERT INTO OrleansQuery(QueryKey, QueryText)VALUES( 'DeleteReminderRowsKey',' DELETE FROM OrleansRemindersTable WHERE ServiceId = @ServiceId AND @ServiceId IS NOT NULL;');