Skip to content

Commit c30ee4c

Browse files
committed
feat: hasura setup script
1 parent 5c9e321 commit c30ee4c

File tree

14 files changed

+798
-0
lines changed

14 files changed

+798
-0
lines changed

pnpm-lock.yaml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/hasura/README.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Hasura Configuration Scripts
2+
3+
This directory contains scripts to configure Hasura metadata, including:
4+
5+
- Tracking tables
6+
- Setting up relationships between tables
7+
- Configuring public permissions
8+
- Tracking custom functions
9+
10+
## Setup
11+
12+
1. Install dependencies:
13+
14+
```bash
15+
pnpm install
16+
```
17+
18+
2. Configure environment variables in the root `.env` file:
19+
20+
```env
21+
HASURA_ENDPOINT=http://localhost:8082 # Your Hasura endpoint
22+
HASURA_ADMIN_SECRET=secret # Your Hasura admin secret
23+
HASURA_SCHEMA=public # Your database schema
24+
```
25+
26+
## Usage
27+
28+
Run the configuration script:
29+
30+
```bash
31+
pnpm configure
32+
```
33+
34+
This will:
35+
36+
1. Clear existing metadata
37+
2. Track all tables in the database
38+
3. Create relationships between tables
39+
4. Track custom functions
40+
5. Set up public permissions for SELECT operations with a limit of 50 rows
41+
42+
## Tables Configured
43+
44+
The script will configure the following tables:
45+
46+
- projects
47+
- pending_project_roles
48+
- project_roles
49+
- rounds
50+
- pending_round_roles
51+
- round_roles
52+
- applications
53+
- applications_payouts
54+
- donations
55+
- legacy_projects
56+
57+
## Relationships
58+
59+
The script sets up the following relationships:
60+
61+
### Array Relationships (One-to-Many)
62+
63+
#### Projects
64+
65+
- Has many applications
66+
- Has many projectRoles
67+
- Has many rounds
68+
69+
#### Rounds
70+
71+
- Has many applications
72+
- Has many roundRoles
73+
74+
#### Applications
75+
76+
- Has many applicationsPayouts
77+
78+
### Object Relationships (Many-to-One)
79+
80+
#### Project Roles
81+
82+
- Belongs to project
83+
84+
#### Rounds
85+
86+
- Belongs to project
87+
88+
#### Round Roles
89+
90+
- Belongs to round
91+
92+
#### Applications
93+
94+
- Belongs to project
95+
- Belongs to round
96+
97+
#### Applications Payouts
98+
99+
- Belongs to application
100+
101+
## Custom Functions
102+
103+
The script tracks the following custom functions:
104+
105+
- search_projects
106+
107+
## Development
108+
109+
```bash
110+
# Run type checking
111+
pnpm check-types
112+
113+
# Run linting
114+
pnpm lint
115+
116+
# Run tests
117+
pnpm test
118+
119+
# Format code
120+
pnpm format:fix
121+
```

scripts/hasura/package.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "@grants-stack-indexer/hasura-config-scripts",
3+
"version": "1.0.0",
4+
"description": "Scripts to configure Hasura metadata",
5+
"license": "MIT",
6+
"author": "Wonderland",
7+
"type": "module",
8+
"directories": {
9+
"src": "src"
10+
},
11+
"files": [
12+
"package.json"
13+
],
14+
"scripts": {
15+
"build": "tsc -p tsconfig.build.json",
16+
"check-types": "tsc --noEmit -p ./tsconfig.json",
17+
"clean": "rm -rf dist/",
18+
"configure": "tsx src/configure-hasura.script.ts",
19+
"format": "prettier --check \"{src,test}/**/*.{js,ts,json}\"",
20+
"format:fix": "prettier --write \"{src,test}/**/*.{js,ts,json}\"",
21+
"lint": "eslint \"{src,test}/**/*.{js,ts,json}\"",
22+
"lint:fix": "pnpm lint --fix",
23+
"test": "vitest run --config vitest.config.ts --passWithNoTests",
24+
"test:cov": "vitest run --config vitest.config.ts --coverage --passWithNoTests"
25+
},
26+
"dependencies": {
27+
"axios": "1.7.7",
28+
"dotenv": "16.4.5",
29+
"zod": "3.23.8"
30+
},
31+
"devDependencies": {
32+
"tsx": "4.19.2"
33+
}
34+
}

0 commit comments

Comments
 (0)