We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 20f1248 commit 405c83eCopy full SHA for 405c83e
storage/database.go
@@ -51,10 +51,17 @@ func NewDatabaseStorage(dsn string) (*DatabaseStorage, error) {
51
52
// Create a trigger to call the function after insert or update
53
_, err = pool.Exec(ctx, `
54
- CREATE TRIGGER clean_expired_cache_trigger
55
- AFTER INSERT OR UPDATE ON cache
56
- FOR EACH ROW
57
- EXECUTE FUNCTION clean_expired_cache();
+ DO $$
+ BEGIN
+ IF NOT EXISTS (
+ SELECT 1 FROM pg_trigger WHERE tgname = 'clean_expired_cache_trigger'
58
+ ) THEN
59
+ CREATE TRIGGER clean_expired_cache_trigger
60
+ AFTER INSERT OR UPDATE ON cache
61
+ FOR EACH ROW
62
+ EXECUTE FUNCTION clean_expired_cache();
63
+ END IF;
64
+ END $$;
65
`)
66
if err != nil {
67
pool.Close()
0 commit comments