feat(filter): 实现发件人黑白名单数据库迁移、控制器与API路由及收件列表联动

This commit is contained in:
xuans committed 2026-09-13 04:33:42 +08:00
1 parent b107090168
commit 48eaba57c1
9 files changed
+498 -38

No files matched your search

+1
View File
@@ -30,6 +30,7 @@ func DefaultMigrations() []Migration {
DefineCustom(18, "expand_operation_log_actor_role", "expand_operation_log_actor_role_v1", applyOperationLogActorRoleSchema),
DefineForDialects(19, "create_user_contacts_and_trusted_senders", userContactStatements()),
DefineCustom(20, "expand_protocol_credential_ciphertext", "expand_protocol_credential_ciphertext_v1", applyProtocolCredentialCiphertextSchema),
DefineCustom(21, "expand_trusted_sender_blacklist", "expand_trusted_sender_blacklist_v1", applyTrustedSenderBlacklistSchema),
}
}
+10
View File
@@ -62,6 +62,15 @@ func TestDefaultMigrationsCreateCompleteSQLiteSchema(t *testing.T) {
if !exists {
t.Fatal("column operation_log.actor_role was not created")
}
for _, column := range []string{"filter_type", "updated_at"} {
exists, err := columnExists(context.Background(), db, DialectSQLite, "user_trusted_sender", column)
if err != nil {
t.Fatal(err)
}
if !exists {
t.Fatalf("column user_trusted_sender.%s was not created", column)
}
}
}
func sqliteIndexExists(t *testing.T, db *sql.DB, index string) bool {
@@ -285,6 +294,7 @@ func TestDefaultMigrationChecksumsAreImmutable(t *testing.T) {
18: "17622df3406657f199d78a3a1aa1f3a8693baf85aa7707910cc6d6cb44c13ee4",
19: "f24b94ca9e4c25b7973f6c15fcaddccc7f02bcf7886c0a4995d2f7b79f4a3a16",
20: "e0bc01f4c2df742bc23c519c2a399cc1c3f341565dbed014509a8c63d68bf725",
21: "ac1a0b3be90128c0e0512d2cec858f8cd7e70abc5ff4734d7113b9674f08dbb0",
}
migrations := DefaultMigrations()
if len(migrations) != len(expected) {
@@ -0,0 +1,33 @@
package migration
import (
"context"
"fmt"
)
func applyTrustedSenderBlacklistSchema(ctx context.Context, exec executor, dialect Dialect) error {
filterTypeDefinitions := map[Dialect]string{
DialectSQLite: "TEXT NOT NULL DEFAULT 'whitelist'",
DialectMySQL: "VARCHAR(20) NOT NULL DEFAULT 'whitelist'",
DialectPostgres: "VARCHAR(20) NOT NULL DEFAULT 'whitelist'",
}
updatedAtDefinitions := map[Dialect]string{
DialectSQLite: "DATETIME NULL",
DialectMySQL: "DATETIME(6) NULL",
DialectPostgres: "TIMESTAMPTZ NULL",
}
ftDef, ok := filterTypeDefinitions[dialect]
if !ok {
return fmt.Errorf("unsupported migration dialect %q for filter_type", dialect)
}
if err := ensureColumn(ctx, exec, dialect, "user_trusted_sender", "filter_type", ftDef); err != nil {
return err
}
upDef, ok := updatedAtDefinitions[dialect]
if !ok {
return fmt.Errorf("unsupported migration dialect %q for updated_at", dialect)
}
return ensureColumn(ctx, exec, dialect, "user_trusted_sender", "updated_at", upDef)
}