Skip to content

Commit

Permalink
Merge pull request #35 from joshuaisaact/trip-fix
Browse files Browse the repository at this point in the history
feat: update trips. share trips. share trip table
  • Loading branch information
joshuaisaact authored Nov 27, 2024
2 parents b5743b3 + 435e4e8 commit 23fa353
Show file tree
Hide file tree
Showing 26 changed files with 1,887 additions and 28 deletions.
47 changes: 23 additions & 24 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
Expand All @@ -33,25 +31,22 @@ jobs:
key: ${{ secrets.SSH_KEY }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
script: |
# Create a backup directory if it doesn't exist
mkdir -p /home/wooster/backend/backup
cd /home/wooster/backend
# Create backup directory
mkdir -p backup
# Stop the server
pm2 stop wooster-server || true
pm2 stop backend || true
# Backup current version (just in case)
timestamp=$(date +%Y%m%d_%H%M%S)
tar -czf /home/wooster/backend/backup/backup_${timestamp}.tar.gz /home/wooster/backend/dist /home/wooster/backend/src || true
# Backup current version
if [ -d "dist" ]; then
timestamp=$(date +%Y%m%d_%H%M%S)
tar -czf backup/backup_${timestamp}.tar.gz dist src || true
fi
# Clean the deployment directory while preserving important files
cd /home/wooster/backend
find . -mindepth 1 -maxdepth 1 \
! -name 'node_modules' \
! -name '.env' \
! -name 'backup' \
! -name 'logs' \
! -name 'pm2' \
-exec rm -rf {} +
# Clean the deployment directory
sudo rm -rf dist build src package.json package-lock.json tsconfig.json .eslintrc.* README.md
- name: Deploy to server
uses: appleboy/scp-action@master
Expand All @@ -64,7 +59,7 @@ jobs:
target: '/home/wooster/backend'
strip_components: 0

- name: Restart application
- name: Post-deploy setup
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
Expand All @@ -74,18 +69,22 @@ jobs:
script: |
cd /home/wooster/backend
# Install production dependencies if needed
# Install production dependencies
npm ci --production
# Ensure correct permissions
chmod +x dist/index.js
# Restart the application
pm2 restart wooster-server || pm2 start dist/index.js --name wooster-server
# Start/restart the application
pm2 describe backend > /dev/null
if [ $? -eq 0 ]; then
pm2 restart backend --update-env
else
pm2 start dist/index.js --name backend
fi
# Save PM2 config
pm2 save
# Clean old backups (keep last 5)
cd backup
ls -t | tail -n +6 | xargs -r rm --
cd backup && ls -t | tail -n +6 | xargs -r rm --
2 changes: 2 additions & 0 deletions drizzle/20241124234923_majestic_polaris.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE "trips" ADD COLUMN "title" text;--> statement-breakpoint
ALTER TABLE "trips" ADD COLUMN "description" text;
1 change: 1 addition & 0 deletions drizzle/20241126065951_odd_reavers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "trips" ADD COLUMN "status" text DEFAULT 'PLANNING' NOT NULL;
15 changes: 15 additions & 0 deletions drizzle/20241126124900_strong_tyger_tiger.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CREATE TABLE IF NOT EXISTS "shared_trips" (
"id" serial PRIMARY KEY NOT NULL,
"user_id" uuid NOT NULL,
"trip_id" serial NOT NULL,
"share_code" text NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"expires_at" timestamp with time zone,
CONSTRAINT "shared_trips_share_code_unique" UNIQUE("share_code")
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "shared_trips" ADD CONSTRAINT "shared_trips_trip_id_trips_trip_id_fk" FOREIGN KEY ("trip_id") REFERENCES "public"."trips"("trip_id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
Loading

0 comments on commit 23fa353

Please sign in to comment.