-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
797 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
SET | ||
statement_timeout = 0; | ||
|
||
--bun:split | ||
DROP TABLE IF EXISTS installations; | ||
|
||
--bun:split | ||
DROP TABLE IF EXISTS key_packages; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
SET | ||
statement_timeout = 0; | ||
|
||
--bun:split | ||
CREATE TABLE installations ( | ||
id TEXT PRIMARY KEY, | ||
wallet_address TEXT NOT NULL, | ||
created_at BIGINT NOT NULL, | ||
revoked_at BIGINT | ||
); | ||
|
||
--bun:split | ||
CREATE TABLE key_packages ( | ||
id TEXT PRIMARY KEY, | ||
installation_id TEXT NOT NULL, | ||
created_at BIGINT NOT NULL, | ||
consumed_at BIGINT, | ||
is_last_resort BOOLEAN NOT NULL, | ||
data BYTEA NOT NULL, | ||
-- Add a foreign key constraint to ensure key packages cannot be added for unregistered installations | ||
CONSTRAINT fk_installation_id FOREIGN KEY (installation_id) REFERENCES installations (id) | ||
); | ||
|
||
--bun:split | ||
CREATE INDEX idx_installations_wallet_address ON installations(wallet_address); | ||
|
||
--bun:split | ||
CREATE INDEX idx_installations_created_at ON installations(created_at); | ||
|
||
--bun:split | ||
CREATE INDEX idx_installations_revoked_at ON installations(revoked_at); | ||
|
||
--bun:split | ||
-- Adding indexes for the key_packages table | ||
CREATE INDEX idx_key_packages_installation_id ON key_packages(installation_id); | ||
|
||
--bun:split | ||
CREATE INDEX idx_key_packages_created_at ON key_packages(created_at); | ||
|
||
--bun:split | ||
CREATE INDEX idx_key_packages_consumed_at ON key_packages(consumed_at); | ||
|
||
--bun:split | ||
CREATE INDEX idx_key_packages_is_last_resort ON key_packages(is_last_resort); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package mls | ||
|
||
import ( | ||
"embed" | ||
|
||
"github.com/uptrace/bun/migrate" | ||
) | ||
|
||
var Migrations = migrate.NewMigrations() | ||
|
||
//go:embed *.sql | ||
var sqlMigrations embed.FS | ||
|
||
func init() { | ||
if err := Migrations.Discover(sqlMigrations); err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package mlsstore | ||
|
||
import "github.com/uptrace/bun" | ||
|
||
type Installation struct { | ||
bun.BaseModel `bun:"table:installations"` | ||
|
||
ID string `bun:",pk"` | ||
WalletAddress string `bun:"wallet_address,notnull"` | ||
CreatedAt int64 `bun:"created_at,notnull"` | ||
RevokedAt *int64 `bun:"revoked_at"` | ||
} | ||
|
||
type KeyPackage struct { | ||
bun.BaseModel `bun:"table:key_packages"` | ||
|
||
ID string `bun:",pk"` // ID is the hash of the data field | ||
InstallationId string `bun:"installation_id,notnull"` | ||
CreatedAt int64 `bun:"created_at,notnull"` | ||
ConsumedAt *int64 `bun:"consumed_at"` | ||
IsLastResort bool `bun:"is_last_resort,notnull"` | ||
Data []byte `bun:"data,notnull,type:bytea"` | ||
} |
Oops, something went wrong.