mirror of
https://github.com/phishingclub/phishingclub.git
synced 2026-10-08 00:16:54 +02:00
Initial open source release
This commit is contained in:
commit
11cf01f08e
488 files changed
+97180
No files matched your search
@@ -0,0 +1,23 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Migrater interface {
|
||||
Migrate(db *gorm.DB) error
|
||||
}
|
||||
|
||||
func UniqueIndexNameAndNullCompanyID(db *gorm.DB, tableName string) error {
|
||||
// SQLITE / POSTGRES
|
||||
// ensure name + null company id is unique
|
||||
idx := fmt.Sprintf("CREATE UNIQUE INDEX IF NOT EXISTS idx_%s_name_null_company_id ON %s (name) WHERE (company_id IS NULL)", tableName, tableName)
|
||||
res := db.Exec(idx)
|
||||
if res.Error != nil {
|
||||
return fmt.Errorf("error creating index: %v on table %s", res.Error, tableName)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user