为双端群聊增加端到端加密附件

This commit is contained in:
xhgit committed 2026-11-14 09:05:40 +08:00
1 parent 5988ad6ed6
commit a95a007768
21 files changed
+405 -84

No files matched your search

@@ -0,0 +1,17 @@
CREATE TABLE group_attachments (
group_id uuid NOT NULL,
id uuid NOT NULL,
epoch_id uuid NOT NULL,
sender_device uuid NOT NULL,
ciphertext bytea NOT NULL CHECK (octet_length(ciphertext) BETWEEN 16 AND 8388624),
created_at timestamptz NOT NULL DEFAULT now(),
PRIMARY KEY (group_id,id),
UNIQUE (group_id,epoch_id,sender_device,id),
FOREIGN KEY (group_id,epoch_id,sender_device) REFERENCES group_epoch_devices(group_id,epoch_id,device_id) ON DELETE CASCADE
);
ALTER TABLE group_messages ADD COLUMN attachment_id uuid;
ALTER TABLE group_messages ADD FOREIGN KEY (group_id,epoch_id,sender_device,attachment_id)
REFERENCES group_attachments(group_id,epoch_id,sender_device,id);
CREATE UNIQUE INDEX group_messages_attachment ON group_messages(group_id,attachment_id) WHERE attachment_id IS NOT NULL;
CREATE INDEX group_attachments_expiry ON group_attachments(created_at);
+7 -1
View File
@@ -31,6 +31,9 @@ var groupsMigration string
//go:embed 008_group_transport.sql
var groupTransportMigration string
//go:embed 009_group_attachments.sql
var groupAttachmentsMigration string
func Migrate(ctx context.Context, pool *pgxpool.Pool) error {
tx, err := pool.Begin(ctx)
if err != nil {
@@ -43,7 +46,10 @@ func Migrate(ctx context.Context, pool *pgxpool.Pool) error {
if _, err = tx.Exec(ctx, "CREATE TABLE IF NOT EXISTS schema_migrations (version integer PRIMARY KEY)"); err != nil {
return err
}
for index, migration := range []string{identityMigration, contactsMigration, deliveryMigration, keyPackagesMigration, mlsCredentialsMigration, attachmentsMigration, groupsMigration, groupTransportMigration} {
for index, migration := range []string{
identityMigration, contactsMigration, deliveryMigration, keyPackagesMigration, mlsCredentialsMigration,
attachmentsMigration, groupsMigration, groupTransportMigration, groupAttachmentsMigration,
} {
version := index + 1
var applied bool
if err = tx.QueryRow(ctx, "SELECT EXISTS (SELECT 1 FROM schema_migrations WHERE version=$1)", version).Scan(&applied); err != nil {