This repository has been archived by the owner on Aug 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip(backend): init database automatically with a schema.sql
- Loading branch information
Showing
5 changed files
with
57 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
-- create a new flat table to store catalog execution results | ||
|
||
CREATE TABLE IF NOT EXISTS catalog_execution_statuses | ||
( | ||
id UUID PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, | ||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, | ||
status VARCHAR(255) NOT NULL, | ||
input_payload JSONB NOT NULL | ||
); |
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,14 @@ | ||
use tokio_postgres::Client; | ||
|
||
use crate::errors::QError; | ||
|
||
/// Initialize the database by creating the tables | ||
pub async fn init_database(pg_client: &Client) -> Result<(), QError> { | ||
// read SQL schema from file | ||
let sql_schema = include_str!("../db/schema.sql"); | ||
|
||
// execute SQL schema | ||
let _ = pg_client.batch_execute(sql_schema).await?; | ||
|
||
Ok(()) | ||
} |
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,12 @@ | ||
pub(crate) enum QError {} | ||
use crate::errors::QError::PostgresError; | ||
|
||
#[derive(Debug)] | ||
pub enum QError { | ||
PostgresError(tokio_postgres::Error), | ||
} | ||
|
||
impl From<tokio_postgres::Error> for QError { | ||
fn from(pg_error: tokio_postgres::Error) -> Self { | ||
PostgresError(pg_error) | ||
} | ||
} |
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