refactor: rename database tables for notification entities to improve clarity and consistency

This commit is contained in:
2026-07-02 16:04:18 +08:00
parent c5225d8c97
commit a0d26fa3a3
7 changed files with 51 additions and 51 deletions
+6 -6
View File
@@ -13,7 +13,7 @@ func (s *Store) CreateChannel(ctx context.Context, ch *model.Channel) error {
if err != nil {
return fmt.Errorf("marshal channel config: %w", err)
}
query := `INSERT INTO channel (name, type, config, status) VALUES (?, ?, ?, ?)`
query := `INSERT INTO notification_channel (name, type, config, status) VALUES (?, ?, ?, ?)`
result, err := s.DB.ExecContext(ctx, query, ch.Name, ch.Type, configJSON, ch.Status)
if err != nil {
return fmt.Errorf("create channel: %w", err)
@@ -26,7 +26,7 @@ func (s *Store) CreateChannel(ctx context.Context, ch *model.Channel) error {
func (s *Store) GetChannel(ctx context.Context, id int) (*model.Channel, error) {
var ch model.Channel
var configBytes []byte
row := s.DB.QueryRowContext(ctx, `SELECT id, name, type, config, status, created_at, updated_at FROM channel WHERE id = ?`, id)
row := s.DB.QueryRowContext(ctx, `SELECT id, name, type, config, status, created_at, updated_at FROM notification_channel WHERE id = ?`, id)
if err := row.Scan(&ch.ID, &ch.Name, &ch.Type, &configBytes, &ch.Status, &ch.CreatedAt, &ch.UpdatedAt); err != nil {
return nil, fmt.Errorf("get channel %d: %w", id, err)
}
@@ -38,7 +38,7 @@ func (s *Store) GetChannel(ctx context.Context, id int) (*model.Channel, error)
func (s *Store) GetChannelByName(ctx context.Context, name string) (*model.Channel, error) {
var ch model.Channel
var configBytes []byte
row := s.DB.QueryRowContext(ctx, `SELECT id, name, type, config, status, created_at, updated_at FROM channel WHERE name = ?`, name)
row := s.DB.QueryRowContext(ctx, `SELECT id, name, type, config, status, created_at, updated_at FROM notification_channel WHERE name = ?`, name)
if err := row.Scan(&ch.ID, &ch.Name, &ch.Type, &configBytes, &ch.Status, &ch.CreatedAt, &ch.UpdatedAt); err != nil {
return nil, fmt.Errorf("get channel by name %s: %w", name, err)
}
@@ -48,7 +48,7 @@ func (s *Store) GetChannelByName(ctx context.Context, name string) (*model.Chann
}
func (s *Store) ListChannels(ctx context.Context) ([]model.Channel, error) {
rows, err := s.DB.QueryContext(ctx, `SELECT id, name, type, config, status, created_at, updated_at FROM channel ORDER BY id`)
rows, err := s.DB.QueryContext(ctx, `SELECT id, name, type, config, status, created_at, updated_at FROM notification_channel ORDER BY id`)
if err != nil {
return nil, fmt.Errorf("list channels: %w", err)
}
@@ -73,7 +73,7 @@ func (s *Store) UpdateChannel(ctx context.Context, id int, ch *model.Channel) er
if err != nil {
return fmt.Errorf("marshal channel config: %w", err)
}
query := `UPDATE channel SET name=?, type=?, config=?, status=? WHERE id=?`
query := `UPDATE notification_channel SET name=?, type=?, config=?, status=? WHERE id=?`
_, err = s.DB.ExecContext(ctx, query, ch.Name, ch.Type, configJSON, ch.Status, id)
if err != nil {
return fmt.Errorf("update channel %d: %w", id, err)
@@ -82,7 +82,7 @@ func (s *Store) UpdateChannel(ctx context.Context, id int, ch *model.Channel) er
}
func (s *Store) DeleteChannel(ctx context.Context, id int) error {
_, err := s.DB.ExecContext(ctx, `DELETE FROM channel WHERE id = ?`, id)
_, err := s.DB.ExecContext(ctx, `DELETE FROM notification_channel WHERE id = ?`, id)
if err != nil {
return fmt.Errorf("delete channel %d: %w", id, err)
}