Skip to content

feat: hasura setup script #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ services:
start_period: 5s
networks:
- datalayer
datalayer-graphql-config:
build:
context: .
dockerfile: scripts/hasura/Dockerfile
env_file:
- .env
environment:
HASURA_ENDPOINT: http://datalayer-graphql-api:8080
HASURA_ADMIN_SECRET: ${DATALAYER_HASURA_ADMIN_SECRET:-secret}
HASURA_SCHEMA: public
depends_on:
datalayer-graphql-api:
condition: service_healthy
networks:
- datalayer
indexer-postgres-db:
image: postgres:16
restart: always
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"author": "Wonderland",
"type": "module",
"scripts": {
"api:configure": "pnpm run --filter @grants-stack-indexer/hasura-config-scripts api:configure",
"build": "turbo run build",
"check-types": "turbo run check-types",
"clean": "turbo run clean",
Expand Down
16 changes: 16 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions scripts/hasura/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM node:20-slim
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

WORKDIR /app

# Copy root workspace files first
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml tsconfig.base.json tsconfig.build.json tsconfig.json ./

# Copy the package's files
COPY scripts/hasura scripts/hasura/

# Install dependencies
RUN pnpm install --frozen-lockfile

# Set working directory to the hasura package
WORKDIR /app/scripts/hasura

# Build the project
RUN pnpm build

# Run the configure script
CMD ["pnpm", "api:configure"]
121 changes: 121 additions & 0 deletions scripts/hasura/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Hasura Configuration Scripts

This directory contains scripts to configure Hasura metadata, including:

- Tracking tables
- Setting up relationships between tables
- Configuring public permissions
- Tracking custom functions

## Setup

1. Install dependencies:

```bash
pnpm install
```

2. Configure environment variables in the root `.env` file:

```env
HASURA_ENDPOINT=http://localhost:8082 # Your Hasura endpoint
HASURA_ADMIN_SECRET=secret # Your Hasura admin secret
HASURA_SCHEMA=public # Your database schema
```

## Usage

Run the configuration script:

```bash
pnpm api:configure
```

This will:

1. Clear existing metadata
2. Track all tables in the database
3. Create relationships between tables
4. Track custom functions
5. Set up public permissions for SELECT operations with a limit of 50 rows

## Tables Configured

The script will configure the following tables:

- projects
- pending_project_roles
- project_roles
- rounds
- pending_round_roles
- round_roles
- applications
- applications_payouts
- donations
- legacy_projects

## Relationships

The script sets up the following relationships:

### Array Relationships (One-to-Many)

#### Projects

- Has many applications
- Has many projectRoles
- Has many rounds

#### Rounds

- Has many applications
- Has many roundRoles

#### Applications

- Has many applicationsPayouts

### Object Relationships (Many-to-One)

#### Project Roles

- Belongs to project

#### Rounds

- Belongs to project

#### Round Roles

- Belongs to round

#### Applications

- Belongs to project
- Belongs to round

#### Applications Payouts

- Belongs to application

## Custom Functions

The script tracks the following custom functions:

- search_projects

## Development

```bash
# Run type checking
pnpm check-types

# Run linting
pnpm lint

# Run tests
pnpm test

# Format code
pnpm format:fix
```
34 changes: 34 additions & 0 deletions scripts/hasura/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "@grants-stack-indexer/hasura-config-scripts",
"version": "1.0.0",
"description": "Scripts to configure Hasura metadata",
"license": "MIT",
"author": "Wonderland",
"type": "module",
"directories": {
"src": "src"
},
"files": [
"package.json"
],
"scripts": {
"api:configure": "tsx src/configure-hasura.script.ts",
"build": "tsc -p tsconfig.build.json",
"check-types": "tsc --noEmit -p ./tsconfig.json",
"clean": "rm -rf dist/",
"format": "prettier --check \"{src,test}/**/*.{js,ts,json}\"",
"format:fix": "prettier --write \"{src,test}/**/*.{js,ts,json}\"",
"lint": "eslint \"{src,test}/**/*.{js,ts,json}\"",
"lint:fix": "pnpm lint --fix",
"test": "vitest run --config vitest.config.ts --passWithNoTests",
"test:cov": "vitest run --config vitest.config.ts --coverage --passWithNoTests"
},
"dependencies": {
"axios": "1.7.7",
"dotenv": "16.4.5",
"zod": "3.23.8"
},
"devDependencies": {
"tsx": "4.19.2"
}
}
Loading
Loading