-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathdatabase_setup.sql
More file actions
35 lines (29 loc) · 1.15 KB
/
database_setup.sql
File metadata and controls
35 lines (29 loc) · 1.15 KB
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
-- LearningSteps API Database Setup
-- This file is automatically ran upon the creation of the PostgresSQL container.
-- You will notice the following volume mount in the docker-compose.yml file:
--
-- volumes:
-- - ../database_setup.sql:/docker-entrypoint-initdb.d/database_setup.sql
-- Creates the entries table
CREATE TABLE IF NOT EXISTS entries (
id VARCHAR PRIMARY KEY,
data JSONB NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
updated_at TIMESTAMP WITH TIME ZONE NOT NULL
);
-- Creates an index on created_at for faster queries
CREATE INDEX IF NOT EXISTS idx_entries_created_at ON entries(created_at);
-- Creates an index on the JSON data for faster searches
CREATE INDEX IF NOT EXISTS idx_entries_data_gin ON entries USING GIN (data);
-- Verify the table was created
\d entries;
-- Test with a sample entry (optional)
-- INSERT INTO entries (id, data, created_at, updated_at)
-- VALUES (
-- 'test-123',
-- '{"work": "Learning SQL", "struggle": "Understanding JSON types", "intention": "Practice more queries"}',
-- NOW(),
-- NOW()
-- );
-- Query the test entry
-- SELECT * FROM entries WHERE id = 'test-123';