绑定设备身份并分发一次性 MLS 密钥包
This commit is contained in:
1 parent
f30f01b699
commit
0b17dd07c5
11 files changed
+286
-11
No files matched your search
@@ -0,0 +1,13 @@
|
||||
CREATE TABLE device_key_packages (
|
||||
device_id uuid NOT NULL REFERENCES devices(id) ON DELETE CASCADE,
|
||||
package_hash bytea NOT NULL CHECK (octet_length(package_hash)=32),
|
||||
package bytea NOT NULL CHECK (octet_length(package) BETWEEN 32 AND 8192),
|
||||
signature bytea NOT NULL CHECK (octet_length(signature)=64),
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
claimed_at timestamptz,
|
||||
PRIMARY KEY (device_id, package_hash)
|
||||
);
|
||||
|
||||
CREATE INDEX device_key_packages_available ON device_key_packages(device_id, created_at)
|
||||
WHERE claimed_at IS NULL;
|
||||
CREATE INDEX device_key_packages_expiry ON device_key_packages(created_at);
|
||||
@@ -16,6 +16,9 @@ var contactsMigration string
|
||||
//go:embed 003_delivery.sql
|
||||
var deliveryMigration string
|
||||
|
||||
//go:embed 004_key_packages.sql
|
||||
var keyPackagesMigration string
|
||||
|
||||
func Migrate(ctx context.Context, pool *pgxpool.Pool) error {
|
||||
tx, err := pool.Begin(ctx)
|
||||
if err != nil {
|
||||
@@ -28,7 +31,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, deliveryMigration} {
|
||||
for index, migration := range []string{identityMigration, contactsMigration, deliveryMigration, keyPackagesMigration} {
|
||||
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