Skip to content

Commit

Permalink
fix: add migration files without embedding to binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Sep 1, 2023
1 parent 864cc57 commit 478182b
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/license_headers_check.yml
Expand Up @@ -26,4 +26,5 @@ jobs:
-s=only \
-ignore '.github/workflows/*.yml' \
-ignore '.github/workflows/*.yaml' \
-ignore 'migrations/*.sql' \
.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -8,4 +8,4 @@ indexer.toml

# IDE files
.vscode/
migrations/
# migrations/
2 changes: 2 additions & 0 deletions migrations/20230901142040_cost_models.down.sql
@@ -0,0 +1,2 @@
-- Add down migration script here
DROP TABLE "CostModels";
8 changes: 8 additions & 0 deletions migrations/20230901142040_cost_models.up.sql
@@ -0,0 +1,8 @@
CREATE TABLE IF NOT EXISTS "CostModels"
(
id INT,
deployment VARCHAR NOT NULL,
model TEXT,
variables JSONB,
PRIMARY KEY( deployment )
);
16 changes: 16 additions & 0 deletions migrations/README.md
@@ -0,0 +1,16 @@
# Database Migration setup

Indexer service binary does _NOT_ run database migrations automatically in the program binary, as it might introduce conflicts with the migrations run by indexer agent. Indexer agent is solely responsible for syncing and migrating the database.

The migration files here are included here for testing only.

### Prerequisite: Install sqlx-cli

Run `cargo install sqlx-cli --no-default-features --features native-tls,postgres`

Simple option: run general installation that supports all databases supported by SQLx
`cargo install sqlx-cli`

### Run the migration

Run `sqlx migrate run`
2 changes: 1 addition & 1 deletion service/src/common/indexer_management_client/mod.rs
Expand Up @@ -16,7 +16,7 @@ pub struct QueryRoot;
#[derive(Debug, Clone)]
pub struct IndexerManagementClient {
database: PgPool, // Only referenced
client: Client, // it is Arc
client: Client, // it is Arc
}

impl IndexerManagementClient {
Expand Down
5 changes: 4 additions & 1 deletion service/src/server/routes/cost.rs
Expand Up @@ -11,5 +11,8 @@ pub(crate) async fn graphql_handler(
Extension(schema): Extension<CostSchema>,
Extension(server_options): Extension<ServerOptions>,
) -> GraphQLResponse {
schema.execute(req.into_inner().data(server_options)).await.into()
schema
.execute(req.into_inner().data(server_options))
.await
.into()
}

0 comments on commit 478182b

Please sign in to comment.