Skip to content
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

Fix race condition where two connections both try to create the new month's table #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion lib/pg_audit_log/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ def install
EXECUTE 'SELECT ($1 + INTERVAL ''1 MONTH'')' INTO month_end USING month_start;
create_table_sql := 'CREATE TABLE ' || tablename || ' ( CHECK ( date(occurred_at) >= DATE ''' || month_start || ''' AND date(occurred_at) < DATE ''' ||
month_end || ''' ) ) INHERITS (#{self.table_name})';
EXECUTE create_table_sql;
BEGIN
EXECUTE create_table_sql;
EXCEPTION WHEN duplicate_table THEN
-- do nothing
END;
EXECUTE 'CREATE INDEX ' || tablename || '_occurred_at ON ' || tablename || ' (date(occurred_at))';
EXECUTE insert_sql USING NEW;
RETURN NULL;
Expand Down