Skip to content

Commit c18d3d2

Browse files
committed
Added ping-database workflow and fixed delete-old-trash workflow
1 parent fdbf99d commit c18d3d2

File tree

6 files changed

+135
-8
lines changed

6 files changed

+135
-8
lines changed

.github/workflows/delete-old-trash.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- name: Call Delete API
11-
run: curl -X GET https://https://keep-clone-kappa.vercel.app//api/delete-old-trash
11+
run: curl -X GET https://https://keep-clone-kappa.vercel.app/api/delete-old-trash
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Ping Supabase Database
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 */3 * *' # Runs every 3 days at midnight UTC
6+
7+
jobs:
8+
ping-database:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Ping Supabase Database
12+
run: |
13+
curl -X POST 'https://keep-clone-kappa.vercel.app/api/ping-database' \
14+
-H "Content-Type: application/json" \

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ Thumbs.db
2222
# Vite
2323
vite.config.js.timestamp-*
2424
vite.config.ts.timestamp-*
25+
.qodo

Structure.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Project Structure
2+
3+
📦src
4+
┣ 📂Images
5+
┃ ┗ 📜Screenshot.png
6+
┣ 📂lib
7+
┃ ┣ 📂components
8+
┃ ┃ ┣ 📜GoogleAuth.svelte
9+
┃ ┃ ┣ 📜Navbar.svelte
10+
┃ ┃ ┣ 📜NewNote.svelte
11+
┃ ┃ ┣ 📜NoteActions.ts
12+
┃ ┃ ┣ 📜Notes.svelte
13+
┃ ┃ ┣ 📜Sidebar.svelte
14+
┃ ┃ ┗ 📜Supabase.ts
15+
┃ ┣ 📂hooks
16+
┃ ┃ ┗ 📜is-mobile.svelte.ts
17+
┃ ┣ 📂server
18+
┃ ┃ ┗ 📂db
19+
┃ ┃ ┃ ┣ 📜index.ts
20+
┃ ┃ ┃ ┗ 📜schema.ts
21+
┃ ┗ 📜index.ts
22+
┣ 📂routes
23+
┃ ┣ 📂api
24+
┃ ┃ ┗ 📂delete-old-trash
25+
┃ ┃ ┃ ┗ 📜+server.ts
26+
┃ ┣ 📂Archive
27+
┃ ┃ ┗ 📜+page.svelte
28+
┃ ┣ 📂Notes
29+
┃ ┃ ┗ 📜+page.svelte
30+
┃ ┣ 📂Reminders
31+
┃ ┃ ┗ 📜+page.svelte
32+
┃ ┣ 📂Trash
33+
┃ ┃ ┗ 📜+page.svelte
34+
┃ ┣ 📜+layout.svelte
35+
┃ ┗ 📜+page.svelte
36+
┣ 📂Store
37+
┃ ┗ 📜store.ts
38+
┣ 📂stories
39+
┃ ┣ 📂assets
40+
┃ ┃ ┣ 📜accessibility.png
41+
┃ ┃ ┣ 📜accessibility.svg
42+
┃ ┃ ┣ 📜addon-library.png
43+
┃ ┃ ┣ 📜assets.png
44+
┃ ┃ ┣ 📜avif-test-image.avif
45+
┃ ┃ ┣ 📜context.png
46+
┃ ┃ ┣ 📜discord.svg
47+
┃ ┃ ┣ 📜docs.png
48+
┃ ┃ ┣ 📜figma-plugin.png
49+
┃ ┃ ┣ 📜github.svg
50+
┃ ┃ ┣ 📜share.png
51+
┃ ┃ ┣ 📜styling.png
52+
┃ ┃ ┣ 📜testing.png
53+
┃ ┃ ┣ 📜theming.png
54+
┃ ┃ ┣ 📜tutorials.svg
55+
┃ ┃ ┗ 📜youtube.svg
56+
┃ ┣ 📜button.css
57+
┃ ┣ 📜Button.stories.svelte
58+
┃ ┣ 📜Button.svelte
59+
┃ ┣ 📜Configure.mdx
60+
┃ ┣ 📜header.css
61+
┃ ┣ 📜Header.stories.svelte
62+
┃ ┣ 📜Header.svelte
63+
┃ ┣ 📜page.css
64+
┃ ┣ 📜Page.stories.svelte
65+
┃ ┗ 📜Page.svelte
66+
┣ 📜app.css
67+
┣ 📜app.d.ts
68+
┣ 📜app.html
69+
┗ 📜demo.spec.ts

src/routes/api/delete-old-trash/+server.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,25 @@ import { supabase } from '../../../lib/components/Supabase';
44
export async function GET() {
55
const twoWeeksAgo = new Date();
66
twoWeeksAgo.setDate(twoWeeksAgo.getDate() - 14);
7-
8-
const { error } = await supabase
7+
8+
console.log(`Deleting notes trashed before ${twoWeeksAgo.toISOString()}`);
9+
10+
const { data, error } = await supabase
911
.from('notes')
1012
.delete()
11-
.lte('updated_at', twoWeeksAgo.toISOString()) // Delete only old trashed notes
12-
.eq('trashed', true);
13-
13+
.lte('updated_at', twoWeeksAgo.toISOString())
14+
.eq('trashed', true)
15+
.select(); // Add this to get count of deleted items
16+
1417
if (error) {
18+
console.error('Error deleting trash notes:', error);
1519
return json({ error: error.message }, { status: 500 });
1620
}
17-
18-
return json({ message: 'Old trashed notes deleted' }, { status: 200 });
21+
22+
console.log(`Successfully deleted ${data?.length ?? 0} trashed notes`);
23+
24+
return json({
25+
message: 'Old trashed notes deleted',
26+
count: data?.length ?? 0
27+
}, { status: 200 });
1928
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// src/routes/api/ping-database/+server.ts
2+
3+
import { json } from '@sveltejs/kit';
4+
import { supabase } from '../../../lib/components/Supabase';
5+
6+
export async function POST() {
7+
try {
8+
// Simple query to ping the database
9+
const { error } = await supabase
10+
.from('notes')
11+
.select('id')
12+
.limit(1);
13+
14+
if (error) {
15+
console.error('Error pinging database:', error);
16+
return json({ error: error.message }, { status: 500 });
17+
}
18+
19+
// Log the ping for monitoring
20+
console.log(`Database pinged successfully at ${new Date().toISOString()}`);
21+
22+
return json({
23+
status: 'success',
24+
message: 'Database pinged successfully',
25+
timestamp: new Date().toISOString()
26+
}, { status: 200 });
27+
} catch (err) {
28+
console.error('Unexpected error:', err);
29+
return json({
30+
error: 'Unexpected error occurred',
31+
details: (err as Error).message
32+
}, { status: 500 });
33+
}
34+
}

0 commit comments

Comments
 (0)