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
+7 -7
View File
@@ -17,7 +17,7 @@ func generateAPIKey() string {
func (s *Store) CreateSource(ctx context.Context, src *model.Source) error {
src.APIKey = generateAPIKey()
query := `INSERT INTO source (name, api_key, parse_mode, parse_pattern, status) VALUES (?, ?, ?, ?, ?)`
query := `INSERT INTO notification_source (name, api_key, parse_mode, parse_pattern, status) VALUES (?, ?, ?, ?, ?)`
result, err := s.DB.ExecContext(ctx, query, src.Name, src.APIKey, src.ParseMode, src.ParsePattern, src.Status)
if err != nil {
return fmt.Errorf("create source: %w", err)
@@ -29,7 +29,7 @@ func (s *Store) CreateSource(ctx context.Context, src *model.Source) error {
func (s *Store) GetSource(ctx context.Context, id int) (*model.Source, error) {
var src model.Source
err := s.DB.GetContext(ctx, &src, `SELECT * FROM source WHERE id = ?`, id)
err := s.DB.GetContext(ctx, &src, `SELECT * FROM notification_source WHERE id = ?`, id)
if err != nil {
return nil, fmt.Errorf("get source %d: %w", id, err)
}
@@ -38,7 +38,7 @@ func (s *Store) GetSource(ctx context.Context, id int) (*model.Source, error) {
func (s *Store) GetSourceByAPIKey(ctx context.Context, apiKey string) (*model.Source, error) {
var src model.Source
err := s.DB.GetContext(ctx, &src, `SELECT * FROM source WHERE api_key = ? AND status = 1`, apiKey)
err := s.DB.GetContext(ctx, &src, `SELECT * FROM notification_source WHERE api_key = ? AND status = 1`, apiKey)
if err != nil {
return nil, fmt.Errorf("get source by api_key: %w", err)
}
@@ -47,7 +47,7 @@ func (s *Store) GetSourceByAPIKey(ctx context.Context, apiKey string) (*model.So
func (s *Store) GetSourceByName(ctx context.Context, name string) (*model.Source, error) {
var src model.Source
err := s.DB.GetContext(ctx, &src, `SELECT * FROM source WHERE name = ?`, name)
err := s.DB.GetContext(ctx, &src, `SELECT * FROM notification_source WHERE name = ?`, name)
if err != nil {
return nil, fmt.Errorf("get source by name %s: %w", name, err)
}
@@ -56,7 +56,7 @@ func (s *Store) GetSourceByName(ctx context.Context, name string) (*model.Source
func (s *Store) ListSources(ctx context.Context) ([]model.Source, error) {
var sources []model.Source
err := s.DB.SelectContext(ctx, &sources, `SELECT * FROM source ORDER BY id`)
err := s.DB.SelectContext(ctx, &sources, `SELECT * FROM notification_source ORDER BY id`)
if err != nil {
return nil, fmt.Errorf("list sources: %w", err)
}
@@ -64,7 +64,7 @@ func (s *Store) ListSources(ctx context.Context) ([]model.Source, error) {
}
func (s *Store) UpdateSource(ctx context.Context, id int, src *model.Source) error {
query := `UPDATE source SET name=?, parse_mode=?, parse_pattern=?, status=? WHERE id=?`
query := `UPDATE notification_source SET name=?, parse_mode=?, parse_pattern=?, status=? WHERE id=?`
_, err := s.DB.ExecContext(ctx, query, src.Name, src.ParseMode, src.ParsePattern, src.Status, id)
if err != nil {
return fmt.Errorf("update source %d: %w", id, err)
@@ -73,7 +73,7 @@ func (s *Store) UpdateSource(ctx context.Context, id int, src *model.Source) err
}
func (s *Store) DeleteSource(ctx context.Context, id int) error {
_, err := s.DB.ExecContext(ctx, `DELETE FROM source WHERE id = ?`, id)
_, err := s.DB.ExecContext(ctx, `DELETE FROM notification_source WHERE id = ?`, id)
if err != nil {
return fmt.Errorf("delete source %d: %w", id, err)
}