- Generate all the required files to start on a new GraphJin app
macuser03@macuser03noMacBook-Pro test % graphjin new blog
INFO Created: blog
INFO Created: blog/Dockerfile
INFO Created: blog/docker-compose.yml
INFO Created: blog/config
INFO Created: blog/config/dev.yml
INFO Created: blog/config/prod.yml
INFO Created: blog/config/seed.js
INFO Created: blog/config/migrations
INFO Created: blog/config/migrations/0_init.sql
INFO Created: blog/config/scripts
INFO Created: blog/config/queries
INFO Created: blog/config/queries/getUsers.gql
INFO App initialized: blog
- Modify docker-compose.yml
macuser03@macuser03noMacBook-Pro test % vi blog/docker-compose.yml
services:
# Postgres DB
db:
# image: postgres:12
image: postgres:latest
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
volumes:
- ./data:/var/lib/postgresql/data
- ./config/migrations:/docker-entrypoint-initdb.d
ports:
- "5432:5432"
api:
image: dosco/graphjin:latest
command: serve
environment:
GO_ENV: "development"
volumes:
- ./config:/config
ports:
- "8080:8080"
depends_on:
- db
vi config/dev.yml
vi config/migrations/0_init.sql
-- Write your migrate up statements here
-- 创建 blog_development 数据库
CREATE DATABASE blog_development;
-- 连接到 blog_development 数据库
\c blog_development;
CREATE TABLE users (
id BIGINT NOT NULL PRIMARY KEY,
full_name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
);
CREATE TABLE products (
id BIGINT NOT NULL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
user_id BIGINT,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id)
);
docker compose up
[+] Running 2/0
✔ Container blog-db-1 Created 0.0s
✔ Container blog-api-1 Created 0.0s
Attaching to api-1, db-1
db-1 | The files belonging to this database system will be owned by user "postgres".
db-1 | This user must also own the server process.
db-1 |
db-1 | The database cluster will be initialized with locale "en_US.utf8".
db-1 | The default database encoding has accordingly been set to "UTF8".
db-1 | The default text search configuration will be set to "english".
db-1 |
db-1 | Data page checksums are disabled.
db-1 |
db-1 | fixing permissions on existing directory /var/lib/postgresql/data ... ok
db-1 | creating subdirectories ... ok
db-1 | selecting dynamic shared memory implementation ... posix
db-1 | selecting default max_connections ... 100
db-1 | selecting default shared_buffers ... 128MB
db-1 | selecting default time zone ... Etc/UTC
db-1 | creating configuration files ... ok
api-1 | WARN database ping: failed to connect to `user=postgres database=blog_development`: 172.24.0.2:5432 (db): dial error: dial tcp 172.24.0.2:5432: connect: connection refused
api-1 | WARN database ping: failed to connect to `user=postgres database=blog_development`: 172.24.0.2:5432 (db): dial error: dial tcp 172.24.0.2:5432: connect: connection refused
api-1 | WARN database ping: failed to connect to `user=postgres database=blog_development`: 172.24.0.2:5432 (db): dial error: dial tcp 172.24.0.2:5432: connect: connection refused
api-1 | WARN database ping: failed to connect to `user=postgres database=blog_development`: 172.24.0.2:5432 (db): dial error: dial tcp 172.24.0.2:5432: connect: connection refused
api-1 | WARN database ping: failed to connect to `user=postgres database=blog_development`: 172.24.0.2:5432 (db): dial error: dial tcp 172.24.0.2:5432: connect: connection refused
api-1 | WARN database ping: failed to connect to `user=postgres database=blog_development`: 172.24.0.2:5432 (db): dial error: dial tcp 172.24.0.2:5432: connect: connection refused
db-1 | running bootstrap script ... ok
api-1 | WARN database ping: failed to connect to `user=postgres database=blog_development`: 172.24.0.2:5432 (db): dial error: dial tcp 172.24.0.2:5432: connect: connection refused
api-1 | WARN database ping: failed to connect to `user=postgres database=blog_development`: 172.24.0.2:5432 (db): dial error: dial tcp 172.24.0.2:5432: connect: connection refused
api-1 | WARN database ping: failed to connect to `user=postgres database=blog_development`: 172.24.0.2:5432 (db): dial error: dial tcp 172.24.0.2:5432: connect: connection refused
db-1 | performing post-bootstrap initialization ... ok
api-1 | WARN database ping: failed to connect to `user=postgres database=blog_development`: 172.24.0.2:5432 (db): dial error: dial tcp 172.24.0.2:5432: connect: connection refused
db-1 | syncing data to disk ... ok
db-1 |
db-1 |
db-1 | Success. You can now start the database server using:
db-1 |
db-1 | pg_ctl -D /var/lib/postgresql/data -l logfile start
db-1 |
db-1 | initdb: warning: enabling "trust" authentication for local connections
db-1 | initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
db-1 | waiting for server to start....2024-07-17 10:14:07.729 UTC [48] LOG: starting PostgreSQL 16.3 (Debian 16.3-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
db-1 | 2024-07-17 10:14:07.730 UTC [48] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db-1 | 2024-07-17 10:14:07.743 UTC [51] LOG: database system was shut down at 2024-07-17 10:14:07 UTC
db-1 | 2024-07-17 10:14:07.755 UTC [48] LOG: database system is ready to accept connections
db-1 | done
db-1 | server started
db-1 |
db-1 | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/0_init.sql
api-1 | WARN database ping: failed to connect to `user=postgres database=blog_development`: 172.24.0.2:5432 (db): dial error: dial tcp 172.24.0.2:5432: connect: connection refused
db-1 | CREATE DATABASE
db-1 | You are now connected to database "blog_development" as user "postgres".
db-1 | CREATE TABLE
db-1 | CREATE TABLE
db-1 |
db-1 |
db-1 | waiting for server to shut down...2024-07-17 10:14:08.502 UTC [48] LOG: received fast shutdown request
db-1 | .2024-07-17 10:14:08.504 UTC [48] LOG: aborting any active transactions
db-1 | 2024-07-17 10:14:08.506 UTC [48] LOG: background worker "logical replication launcher" (PID 54) exited with exit code 1
db-1 | 2024-07-17 10:14:08.506 UTC [49] LOG: shutting down
db-1 | 2024-07-17 10:14:08.507 UTC [49] LOG: checkpoint starting: shutdown immediate
db-1 | 2024-07-17 10:14:08.834 UTC [49] LOG: checkpoint complete: wrote 930 buffers (5.7%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.248 s, sync=0.073 s, total=0.328 s; sync files=307, longest=0.001 s, average=0.001 s; distance=4284 kB, estimate=4284 kB; lsn=0/1919390, redo lsn=0/1919390
db-1 | 2024-07-17 10:14:08.883 UTC [48] LOG: database system is shut down
db-1 | done
db-1 | server stopped
db-1 |
db-1 | PostgreSQL init process complete; ready for start up.
db-1 |
db-1 | 2024-07-17 10:14:08.933 UTC [1] LOG: starting PostgreSQL 16.3 (Debian 16.3-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
db-1 | 2024-07-17 10:14:08.933 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db-1 | 2024-07-17 10:14:08.933 UTC [1] LOG: listening on IPv6 address "::", port 5432
db-1 | 2024-07-17 10:14:08.935 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db-1 | 2024-07-17 10:14:08.953 UTC [65] LOG: database system was shut down at 2024-07-17 10:14:08 UTC
db-1 | 2024-07-17 10:14:08.965 UTC [1] LOG: database system is ready to accept connections
api-1 | INFO GraphJin started {"version": "not-set", "host-port": "0.0.0.0:8080", "app-name": "Blog Development", "env": "development", "hot-deploy": false, "production": false, "secrets-used": false}
![[Pasted image 20240717191651.png]]