30 lines
966 B
Go
30 lines
966 B
Go
package models
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/uptrace/bun"
|
|
)
|
|
|
|
type BlackList struct {
|
|
bun.BaseModel `bun:"table:blacklist"`
|
|
UserID int64 `bun:",pk,autoincrement"`
|
|
Name string `bun:"name,type:text,unique" json:"name" yaml:"name"`
|
|
TelegramID int64 `bun:"telegram_id,type:int,unique" json:"telegram_id" yaml:"telegram_id"`
|
|
TelegramUsername string `bun:"telegram_username,type:text,unique" json:"telegram_username" yaml:"telegram_username"`
|
|
}
|
|
|
|
var _ bun.AfterCreateTableHook = (*BlackList)(nil)
|
|
|
|
func (*BlackList) AfterCreateTable(ctx context.Context, query *bun.CreateTableQuery) error {
|
|
_, err := query.DB().NewCreateIndex().Model((*BlackList)(nil)).Index("idx_bl_telegram_id").Column("telegram_id").Exec(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
_, err = query.DB().NewCreateIndex().Model((*BlackList)(nil)).Index("idx_bl_telegram_username").Column("telegram_username").Exec(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|