实现 MLS 设备封包投递与离线同步
This commit is contained in:
1 parent
53164d0fa8
commit
f30f01b699
15 files changed
+366
-16
No files matched your search
@@ -0,0 +1,13 @@
|
||||
CREATE TABLE device_envelopes (
|
||||
sequence bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
message_id uuid NOT NULL,
|
||||
sender_device uuid NOT NULL REFERENCES devices(id) ON DELETE CASCADE,
|
||||
recipient_device uuid NOT NULL REFERENCES devices(id) ON DELETE CASCADE,
|
||||
ciphertext bytea NOT NULL CHECK (octet_length(ciphertext) BETWEEN 16 AND 65536),
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
UNIQUE (sender_device, recipient_device, message_id),
|
||||
CHECK (sender_device <> recipient_device)
|
||||
);
|
||||
|
||||
CREATE INDEX device_envelopes_inbox ON device_envelopes(recipient_device, sequence);
|
||||
CREATE INDEX device_envelopes_expiry ON device_envelopes(created_at);
|
||||
@@ -13,6 +13,9 @@ var identityMigration string
|
||||
//go:embed 002_contacts.sql
|
||||
var contactsMigration string
|
||||
|
||||
//go:embed 003_delivery.sql
|
||||
var deliveryMigration string
|
||||
|
||||
func Migrate(ctx context.Context, pool *pgxpool.Pool) error {
|
||||
tx, err := pool.Begin(ctx)
|
||||
if err != nil {
|
||||
@@ -25,7 +28,7 @@ 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} {
|
||||
for index, migration := range []string{identityMigration, contactsMigration, deliveryMigration} {
|
||||
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 {
|
||||
|
||||
Reference in new issue
Block a user