29 lines
772 B
SQL
29 lines
772 B
SQL
CREATE EXTENSION IF NOT EXISTS pg_trgm;
|
|
|
|
CREATE TABLE IF NOT EXISTS user_profiles (
|
|
user_id UUID PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE,
|
|
display_name TEXT,
|
|
full_name TEXT,
|
|
avatar_url TEXT,
|
|
bio TEXT,
|
|
location TEXT,
|
|
website TEXT,
|
|
country_code CHAR(2),
|
|
phone TEXT,
|
|
created_at TIMESTAMPTZ DEFAULT now(),
|
|
updated_at TIMESTAMPTZ DEFAULT now()
|
|
);
|
|
|
|
CREATE INDEX idx_user_profiles_display_name
|
|
ON user_profiles USING gin (display_name gin_trgm_ops);
|
|
|
|
CREATE INDEX idx_user_profiles_country
|
|
ON user_profiles(country_code);
|
|
|
|
CREATE UNIQUE INDEX idx_user_profiles_phone
|
|
ON user_profiles(phone);
|
|
|
|
CREATE TRIGGER trigger_user_profiles_updated_at
|
|
BEFORE UPDATE ON user_profiles
|
|
FOR EACH ROW
|
|
EXECUTE FUNCTION update_updated_at(); |