-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from nightly-labs/more-db-schemas
More db schemas
- Loading branch information
Showing
26 changed files
with
855 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
CREATE TABLE sessions( | ||
session_id TEXT NOT NULL UNIQUE, | ||
app_id TEXT NOT NULL, | ||
app_metadata TEXT NOT NULL, | ||
app_ip_address TEXT NOT NULL, | ||
persistent BOOLEAN NOT NULL, | ||
network TEXT NOT NULL, | ||
client_id TEXT, | ||
client_device TEXT, | ||
client_metadata TEXT, | ||
client_notification_endpoint TEXT, | ||
client_connected_at BIGINT, | ||
session_open_timestamp BIGINT NOT NULL, | ||
session_close_timestamp BIGINT | ||
); | ||
|
||
CREATE UNIQUE INDEX sessions_session_id ON sessions(session_id); | ||
|
||
ALTER TABLE sessions | ||
ADD CONSTRAINT fk_sessions_registered_apps | ||
FOREIGN KEY (app_id) | ||
REFERENCES registered_apps (app_id) | ||
ON DELETE CASCADE; |
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 @@ | ||
CREATE TYPE request_status_enum AS ENUM ( | ||
'Pending', | ||
'Completed', | ||
'Failed', | ||
'Rejected', | ||
'TimedOut', | ||
'Unknown' | ||
); |
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,16 @@ | ||
CREATE TABLE requests( | ||
request_id TEXT NOT NULL UNIQUE, | ||
request_type TEXT NOT NULL, | ||
session_id TEXT NOT NULL, | ||
request_status request_status_enum NOT NULL, | ||
network TEXT NOT NULL, | ||
creation_timestamp BIGINT NOT NULL | ||
); | ||
|
||
CREATE UNIQUE INDEX requests_request_id ON requests(request_id); | ||
|
||
ALTER TABLE requests | ||
ADD CONSTRAINT fk_requests_sessions | ||
FOREIGN KEY (session_id) | ||
REFERENCES sessions (session_id) | ||
ON DELETE CASCADE; |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod db; | ||
pub mod structs; | ||
pub mod tables; |
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 @@ | ||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub struct ClientData { | ||
pub client_id: Option<String>, | ||
pub device: Option<String>, | ||
pub metadata: Option<String>, | ||
pub notification_endpoint: Option<String>, | ||
pub connected_at: u64, // Timestamp of when the client connected to the session | ||
} |
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,3 @@ | ||
pub const LAST_24_HOURS: &str = "EXTRACT(EPOCH FROM NOW() - INTERVAL '1 day')::BIGINT * 1000"; | ||
pub const LAST_7_DAYS: &str = "EXTRACT(EPOCH FROM NOW() - INTERVAL '7 days')::BIGINT * 1000"; | ||
pub const LAST_30_DAYS: &str = "EXTRACT(EPOCH FROM NOW() - INTERVAL '30 days')::BIGINT * 1000"; |
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,4 @@ | ||
pub mod client_data; | ||
pub mod consts; | ||
pub mod request_status; | ||
pub mod subscription; |
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,10 @@ | ||
use sqlx::Type; | ||
|
||
#[derive(Clone, Debug, Eq, PartialEq, Type)] | ||
#[sqlx(type_name = "request_status_enum")] | ||
pub enum RequestStatus { | ||
Pending, | ||
Completed, | ||
Rejected, | ||
TimedOut, | ||
} |
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,9 @@ | ||
use sqlx::Type; | ||
|
||
#[derive(Clone, Debug, Eq, PartialEq, Type)] | ||
#[sqlx(type_name = "subscription")] | ||
pub struct Subscription { | ||
pub subscription_type: String, | ||
pub valid_from: i64, | ||
pub valid_till: i64, | ||
} |
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 |
---|---|---|
@@ -1 +1,5 @@ | ||
pub mod registered_app; | ||
pub mod requests; | ||
pub mod sessions; | ||
pub mod test_utils; | ||
pub mod utils; |
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
Oops, something went wrong.