GenerateCreateTableQuery returns the query for creating the queue table
(queueName string)
| 9 | |
| 10 | // GenerateCreateTableQuery returns the query for creating the queue table |
| 11 | func GenerateCreateTableQuery(queueName string) string { |
| 12 | quotedTableName := pg.QuoteIdentifier(queueName) |
| 13 | return fmt.Sprintf(`CREATE TABLE IF NOT EXISTS %[1]s |
| 14 | ( |
| 15 | id UUID DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, |
| 16 | created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL, |
| 17 | started_at TIMESTAMPTZ NULL, |
| 18 | locked_until TIMESTAMPTZ NULL, |
| 19 | scheduled_for TIMESTAMPTZ NULL, |
| 20 | processed_at TIMESTAMPTZ NULL, |
| 21 | consumed_count INTEGER DEFAULT 0 NOT NULL, |
| 22 | error_detail TEXT NULL, |
| 23 | payload JSONB NOT NULL, |
| 24 | metadata JSONB NOT NULL |
| 25 | ); |
| 26 | CREATE INDEX IF NOT EXISTS "%[2]s_created_at_idx" ON %[1]s (created_at); |
| 27 | CREATE INDEX IF NOT EXISTS "%[2]s_processed_at_null_idx" ON %[1]s (processed_at) WHERE (processed_at IS NULL); |
| 28 | CREATE INDEX IF NOT EXISTS "%[2]s_scheduled_for_idx" ON %[1]s (scheduled_for ASC NULLS LAST) WHERE (processed_at IS NULL); |
| 29 | CREATE INDEX IF NOT EXISTS "%[2]s_metadata_idx" ON %[1]s USING GIN(metadata) WHERE processed_at IS NULL; |
| 30 | `, quotedTableName, quotedTableName[1:len(quotedTableName)-1]) |
| 31 | } |
| 32 | |
| 33 | // GenerateDropTableQuery returns a postgres query for dropping the queue table |
| 34 | func GenerateDropTableQuery(queueName string) string { |