forked from Kanba-co/kanba
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit-db.sql
More file actions
40 lines (35 loc) · 1005 Bytes
/
Copy pathinit-db.sql
File metadata and controls
40 lines (35 loc) · 1005 Bytes
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
-- Database initialization script for Kanba
-- This script runs when the PostgreSQL container starts
-- Create the database if it doesn't exist
-- (This is handled by the POSTGRES_DB environment variable)
-- Create extensions that might be useful
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
-- Create a function to generate slugs
CREATE OR REPLACE FUNCTION generate_slug(input_text TEXT)
RETURNS TEXT AS $$
BEGIN
RETURN lower(
regexp_replace(
regexp_replace(
regexp_replace(input_text, '[^a-zA-Z0-9\s-]', '', 'g'),
'\s+', '-', 'g'
),
'-+', '-', 'g'
)
);
END;
$$ LANGUAGE plpgsql;
-- Create a function to update updated_at timestamp
CREATE OR REPLACE FUNCTION update_updated_at_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = now();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
-- Log that initialization is complete
DO $$
BEGIN
RAISE NOTICE 'Kanba database initialization completed successfully!';
END $$;