-
Notifications
You must be signed in to change notification settings - Fork 0
/
justfile
127 lines (101 loc) · 4.1 KB
/
justfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
set dotenv-load := true
# List available recipes in the order in which they appear in this file
_default:
@just --list --unsorted
# Reset and reseed database, and regenerate Keysely type definitions
reset-db:
rm -f $APP_DATABASE_PATH
npx tsx migrate.ts
npx tsx seed.ts
# reset-db and also delete vote and score events files
reset-all:
rm -rf ~/social-protocols-data/*.db
rm -rf ~/social-protocols-data/*.db-wal
rm -rf ~/social-protocols-data/*.db-shm
mkdir -p ~/social-protocols-data
rm -f "$GB_DATABASE_PATH"
just reset-db
# run the migration script
migrate:
npx tsx migrate.ts
# run the app locally and watch for changes
dev:
npm install
npm run dev
# open database in sqlite commandline
db:
sqlite3 $APP_DATABASE_PATH
# run typescript typechecker
typecheck:
npx tsc --noEmit --watch
# run linters and formatter
lint:
CI=true npx eslint . --fix
# run all tests non-e2e tests
test:
npm run test
# run all e2e tests
e2e-test:
npm run test:e2e:dev
# retrun seed script
reseed:
npx tsx seed.ts
# import json.gz file containing conversations from HN
import-hn:
npx tsx import-hn.ts ./other/hn-data/*.json.gz
import-society-library json userid:
npx tsx other/import-society-library-debatemap.ts {{json}} {{userid}}
# delete local database, download production database
download-prod-db:
rm -f "$APP_DATABASE_PATH"
rm -f "$APP_DATABASE_PATH"-shm
rm -f "$APP_DATABASE_PATH"-wal
flyctl ssh console -C "sqlite3 /data/sqlite.db '.backup /data/backup.db'"
flyctl ssh sftp get /data/backup.db "$APP_DATABASE_PATH" || true
# build the docker container
docker-build:
earthly +docker-image
docker image ls
# docker-build with --platform linux/amd64
docker-build-mac:
docker build --platform linux/amd64 . -t deploy-sn
# run the app in the docker container (you must run docker-build first)
docker-run:
docker-compose up
# exec /bin/bash in the running docker container
docker-exec:
docker exec -it deploy-sn /bin/bash
# download a copy of the production database to $SOCIAL_PROTOCOLS_DATADIR/production/. will not override local database unless you run use-production-data
download-production-data:
# todo: use sqlite .backup command and download copy
rm -rf $SOCIAL_PROTOCOLS_DATADIR/production/
mkdir -p $SOCIAL_PROTOCOLS_DATADIR/production/
fly ssh sftp get /data/sqlite.db $SOCIAL_PROTOCOLS_DATADIR/production/sqlite.db
fly ssh sftp get /data/global-brain.db $SOCIAL_PROTOCOLS_DATADIR/production/global-brain.db
fly ssh sftp get /data/sqlite.db-wal $SOCIAL_PROTOCOLS_DATADIR/production/sqlite.db-wal
fly ssh sftp get /data/global-brain.db-wal $SOCIAL_PROTOCOLS_DATADIR/production/global-brain.db-wal
# use the data in $SOCIAL_PROTOCOLS_DATADIR/production/ locally. Run download-production-data first
use-production-data:
cp -f $SOCIAL_PROTOCOLS_DATADIR/production/sqlite.db $SOCIAL_PROTOCOLS_DATADIR/
cp -f $SOCIAL_PROTOCOLS_DATADIR/production/global-brain.db $SOCIAL_PROTOCOLS_DATADIR/
cp -f $SOCIAL_PROTOCOLS_DATADIR/production/sqlite.db-wal $SOCIAL_PROTOCOLS_DATADIR/
cp -f $SOCIAL_PROTOCOLS_DATADIR/production/global-brain.db-wal $SOCIAL_PROTOCOLS_DATADIR/
just migrate
just replay-vote-events
# open sqlite3 console on production database
production-db:
fly ssh console -C 'sqlite3 /data/sqlite.db'
install-node-extension-from-earthly:
earthly --artifact +globalbrain-node-package/artifact ./GlobalBrain.jl/globalbrain-node
(cd ./GlobalBrain.jl/globalbrain-node && npm install)
npm install --ignore-scripts --save './GlobalBrain.jl/globalbrain-node'
replay-vote-events:
rm -f $SOCIAL_PROTOCOLS_DATADIR/global-brain.db
sqlite3 $APP_DATABASE_PATH "delete from effectEvent where 1=1"
sqlite3 $APP_DATABASE_PATH "delete from effect where 1=1"
sqlite3 $APP_DATABASE_PATH "delete from score where 1=1"
sqlite3 $APP_DATABASE_PATH "delete from scoreEvent where 1=1"
time npx tsx other/replay-vote-events.ts
# show a list of recently active sessions in production
prod-sessions:
flyctl ssh console -C 'bash -c "sqlite3 $APP_DATABASE_PATH \"select datetime(updatedAt / 1000, '"'"'unixepoch'"'"') as updated, email, username from Session join User on Session.UserId = User.id order by updatedAt asc;\""'