diff --git a/docker-compose.yml b/docker-compose.yml index b0af468..8fc50c1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,11 +3,11 @@ services: image: postgres:15 restart: unless-stopped environment: - POSTGRES_USER: xcvr - POSTGRES_PASSWORD: secret - POSTGRES_DB: xcvrdb + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + POSTGRES_DB: ${POSTGRES_DB} ports: - - "15432:5432" + - "${POSTGRES_PORT}:5432" volumes: - dbdata:/var/lib/posgresql/data diff --git a/migratedown b/migratedown index fcfb0dc..eeeca64 100755 --- a/migratedown +++ b/migratedown @@ -1,2 +1,4 @@ #!/bin/bash -migrate -path migrations -database "postgres://xcvr:secret@localhost:15432/xcvrdb?sslmode=disable" down \ No newline at end of file +source .env + +migrate -path migrations -database "postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:$POSTGRES_PORT/$POSTGRES_DB?sslmode=disable" down \ No newline at end of file diff --git a/migrateup b/migrateup index 2a17595..a165059 100755 --- a/migrateup +++ b/migrateup @@ -1,2 +1,4 @@ #!/bin/bash -migrate -path migrations -database "postgres://xcvr:secret@localhost:15432/xcvrdb?sslmode=disable" up \ No newline at end of file +source .env + +migrate -path migrations -database "postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:$POSTGRES_PORT/$POSTGRES_DB?sslmode=disable" up \ No newline at end of file diff --git a/migrations/002_init.down.sql b/migrations/001_init.down.sql similarity index 100% rename from migrations/002_init.down.sql rename to migrations/001_init.down.sql diff --git a/migrations/002_populate.down.sql b/migrations/002_populate.down.sql new file mode 100644 index 0000000..01ff7de --- /dev/null +++ b/migrations/002_populate.down.sql @@ -0,0 +1,5 @@ +DELETE FROM messages; +DELETE FROM signets; +DELETE FROM channels; +DELETE FROM did_handle; +DELETE FROM profiles; \ No newline at end of file diff --git a/migrations/002_populate.up.sql b/migrations/002_populate.up.sql new file mode 100644 index 0000000..ac25f9a --- /dev/null +++ b/migrations/002_populate.up.sql @@ -0,0 +1,24 @@ +INSERT INTO profiles (did, display_name, default_nick, status, avatar_cid, avatar_mime, color, uri, cid) +VALUES +('did:example:alice', 'Alice Example', 'alice', 'Chilling', 'bafybeib6...', 'image/png', 16711680, 'at://did:example:alice/app.bsky.actor.profile/self', 'cid1'), +('did:example:bob', 'Bob Example', 'bobby', 'Working hard', 'bafybeib7...', 'image/jpeg', 65280, 'at://did:example:bob/app.bsky.actor.profile/self', 'cid2'); + +INSERT INTO did_handle (handle, did) +VALUES +('alice.com', 'did:example:alice'), +('bob.net', 'did:example:bob'); + +INSERT INTO channels (uri, cid, did, host, title, topic, created_at) +VALUES +('at://did:example:alice/org.xcvr.channel/general', 'chanCid1', 'did:example:alice', 'alice.com', 'General Chat', 'All-purpose chatter', now() - interval '2 days'), +('at://did:example:bob/org.xcvr.channel/help', 'chanCid2', 'did:example:bob', 'bob.net', 'Help Channel', 'Support and help', now() - interval '1 day'); + +INSERT INTO signets (uri, did, channel_uri, message_id, cid) +VALUES +('at://did:example:alice/org.xcvr.lrc/signet1', 'did:example:alice', 'at://did:example:alice/org.xcvr.channel/general', 1, 'signetCid1'), +('at://did:example:bob/org.xcvr.lrc/signet2', 'did:example:bob', 'at://did:example:bob/org.xcvr.channel/help', 2, 'signetCid2'); + +INSERT INTO messages (uri, did, signet_uri, body, nick, color, cid) +VALUES +('at://did:example:alice/org.xcvr.lrc.message/msg1', 'did:example:alice', 'at://did:example:alice/org.xcvr.lrc/signet1', 'Hey, welcome to the general chat!', 'alice', 16711680, 'msgCid1'), +('at://did:example:bob/org.xcvr.lrc.message/msg2', 'did:example:bob', 'at://did:example:bob/org.xcvr.lrc/signet2', 'How can I help you today?', 'bobby', 65280, 'msgCid2'); \ No newline at end of file diff --git a/psql b/psql index 3b6c0f3..452f52c 100755 --- a/psql +++ b/psql @@ -1,2 +1,4 @@ #!/bin/bash -docker exec -it xcvr-backend-db-1 psql -U xcvr -d xcvrdb \ No newline at end of file +source .env + +docker exec -it xcvr-backend-db-1 psql -U $POSTGRES_USER -d $POSTGRES_DB \ No newline at end of file