Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/cic_graph?schema=public"
128 changes: 128 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
.env
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.*
!.env.example

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# vitepress build output
**/.vitepress/dist

# vitepress cache directory
**/.vitepress/cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
21 changes: 0 additions & 21 deletions Dockerfile

This file was deleted.

56 changes: 25 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,39 @@
# cic-graph

![GitHub release (latest by date)](https://img.shields.io/github/v/tag/grassrootseconomics/cic-graph)

> CIC Graph

Central CIC Stack Postgres store specifically for indexing:

- Transactional data from the chain
- Custodial user data (PII, custodial client data)
- Voucher data (backers, certifications, e.t.c.)
- VPAs (Virtual Payment Addresses)
- Marketplace data (proposed)
## Dev
### Docker
To run the application in a Docker container, you can use the following command:

Relationships, check constraints and referential integrity are built in at the Postgres level. However, CIC Graph is meant to be complemented by secondary backend services to provide CRUD and any other important functionality around it.
```bash
cd dev
docker compose up
```
### Install dependencies

Primarily **Hasura** is supported as a GraphQL proxy backend infront of it. Aditionally, other 3rd party proxies such as **Supabase** and **PostgREST** are expected to work on top of the Postgres schema defined in `migrations`.
```bash
pnpm install
```

## Hasura Development

**Prerequisites**
### Development

- Docker and Docker Compose (latest)
- [tern](https://github.com/jackc/tern)
- [hasura CLI](https://hasura.io/docs/latest/hasura-cli/install-hasura-cli/)
Testing new schema designs or modifications in a local development environment
```bash
pnpm drizzle-kit push
```

Hasura expects a metadata definition consistent with the underlying Postgres schema.

For ease of testing and development, a Docker image which bakes in the migrations and metadata files is provided (`Dockerfile`). The `dev` folder also contains a docker-compose.yaml file to quickly get started.
#### Migrations
To generate a new migration, you can use the following command:

Below is an exmaple of how to add a table and sync the git repo with the changes.
```bash
pnpm drizzle-kit generate
```

### Adding a new table

1. Bring up the containers in `dev` with `docker-compose up -d`.
2. Start the Hasura Console with `hasura console --admin-secret "admin" --endpoint http://localhost:8080`.
3. In the `migrations` folder, run `tern new $MIGRATION_NAME` and write the migration file.
4. Run the migration inside Hasura in the Data manager tab, checking "Track This", "Cascade metadata" and "This is a migration"
5. Run `hasura metadata export --admin-secret "admin" --endpoint http://localhost:8080` to sync the metadata.
7. Git commit.


## License

[AGPL-3.0](LICENSE).
Apply Migration
```bash
pnpm drizzle-kit migrate
```
20 changes: 2 additions & 18 deletions dev/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,8 @@ services:
timeout: 5s
retries: 5
ports:
- '5432:5432'
hasura:
image: ghcr.io/grassrootseconomics/cic-graph/cic-graph:latest
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
environment:
HASURA_GRAPHQL_METADATA_DATABASE_URL: postgres://postgres:postgres@postgres:5432/cic_graph
PG_DATABASE_URL: postgres://postgres:postgres@postgres:5432/cic_graph
HASURA_GRAPHQL_ENABLE_CONSOLE: "true"
HASURA_GRAPHQL_ADMIN_SECRET: admin
HASURA_GRAPHQL_UNAUTHORIZED_ROLE: anonymous
HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
HASURA_GRAPHQL_DEV_MODE: "true"
ports:
- '8080:8080'
- "5432:5432"

volumes:
cic-graph-pg:
driver: local

18 changes: 18 additions & 0 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// drizzle.config.ts

import { config } from "dotenv";
import { defineConfig } from "drizzle-kit";

config();

export default defineConfig({
out: './drizzle',
schema: './src/db/schema.ts',
dialect: 'postgresql',
dbCredentials: {
url: process.env.DATABASE_URL as string,
},
verbose: true,
// Always ask for confirmation
strict: true,
});
86 changes: 0 additions & 86 deletions entrypoint.sh

This file was deleted.

Empty file removed metadata/actions.graphql
Empty file.
6 changes: 0 additions & 6 deletions metadata/actions.yaml

This file was deleted.

1 change: 0 additions & 1 deletion metadata/allow_list.yaml

This file was deleted.

1 change: 0 additions & 1 deletion metadata/api_limits.yaml

This file was deleted.

1 change: 0 additions & 1 deletion metadata/backend_configs.yaml

This file was deleted.

1 change: 0 additions & 1 deletion metadata/cron_triggers.yaml

This file was deleted.

12 changes: 0 additions & 12 deletions metadata/databases/cic_graph/tables/public_account_role_type.yaml

This file was deleted.

Loading