From 8a776368e3ce3f5d29c7b1a4943ff7b055a30675 Mon Sep 17 00:00:00 2001 From: Maciej Gierada Date: Wed, 19 Jun 2024 16:03:55 +0200 Subject: [PATCH] feat: remove unsued test methods --- server/db/db_test.go | 61 -------------------------------------------- 1 file changed, 61 deletions(-) diff --git a/server/db/db_test.go b/server/db/db_test.go index fb36d27..f33e0b3 100644 --- a/server/db/db_test.go +++ b/server/db/db_test.go @@ -99,67 +99,6 @@ func setup() error { return nil } -func createTriggerForCounterTableForTest(db *sql.DB, tableName string) error { - var err error - triggerFunctionName := fmt.Sprintf("%s_update_updated_at_column", tableName) - triggerName := fmt.Sprintf("%s_update_updated_at", tableName) - - createTriggerFunctionQuery := fmt.Sprintf(` - CREATE OR REPLACE FUNCTION %s() - RETURNS TRIGGER AS $$ - BEGIN - NEW.updated_at = now(); - IF NEW.current_value > NEW.max_value THEN - NEW.max_value = NEW.current_value; - END IF; - RETURN NEW; - END; - $$ LANGUAGE plpgsql; - `, triggerFunctionName) - _, err = db.Exec(createTriggerFunctionQuery) - if err != nil { - log.Fatalf("❌ Error creating trigger function for %s table.\n %s", tableName, err) - } - - createTriggerQuery := fmt.Sprintf(` - DO $$ - BEGIN - IF NOT EXISTS ( - SELECT 1 - FROM pg_trigger - WHERE tgname = '%s' - ) THEN - CREATE TRIGGER %s - BEFORE UPDATE ON %s - FOR EACH ROW - EXECUTE FUNCTION %s(); - END IF; - END $$; - `, triggerName, triggerName, tableName, triggerFunctionName) - _, err = db.Exec(createTriggerQuery) - if err != nil { - log.Fatalf("❌ Error creating trigger for %s table.\n %s", tableName, err) - } - return nil -} - -func createCounterTableForTest(db *sql.DB, tableName string) error { - var err error - rawCreateQuery := `CREATE TABLE IF NOT EXISTS %s ( - current_value INT NOT NULL, - max_value INT NULL DEFAULT 0, - is_locked BOOLEAN NOT NULL DEFAULT FALSE, - updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - reseted_at TIMESTAMP NULL DEFAULT NULL - );` - createQuery := fmt.Sprintf(rawCreateQuery, tableName) - _, err = db.Exec(createQuery) - if err != nil { - return fmt.Errorf("failed to create table %s: %w", tableName, err) - } - return nil -} - func createHistoricalCounterForTest(db *sql.DB, tableName string) error { var err error rawCreateQuery := `CREATE TABLE IF NOT EXISTS %s (