Files
Onyva-Postling/config/migrate_add_linkedin_accounts.sql
Ruben Fischer f14515e9cf Major updates: LinkedIn auto-posting, timezone fixes, and Docker improvements
Features:
- Add LinkedIn OAuth integration and auto-posting functionality
- Add scheduler service for automated post publishing
- Add metadata field to generated_posts for LinkedIn URLs
- Add privacy policy page for LinkedIn API compliance
- Add company management features and employee accounts
- Add license key system for company registrations

Fixes:
- Fix timezone issues (use UTC consistently across app)
- Fix datetime serialization errors in database operations
- Fix scheduling timezone conversion (local time to UTC)
- Fix import errors (get_database -> db)

Infrastructure:
- Update Docker setup to use port 8001 (avoid conflicts)
- Add SSL support with nginx-proxy and Let's Encrypt
- Add LinkedIn setup documentation
- Add migration scripts for schema updates

Services:
- Add linkedin_service.py for LinkedIn API integration
- Add scheduler_service.py for background job processing
- Add storage_service.py for Supabase Storage
- Add email_service.py improvements
- Add encryption utilities for token storage

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-11 11:30:20 +01:00

69 lines
2.2 KiB
PL/PgSQL

-- Migration: Add LinkedIn accounts for auto-posting
-- Description: Allows employees to link their LinkedIn accounts for automatic post publishing
CREATE TABLE IF NOT EXISTS linkedin_accounts (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
-- LinkedIn Identity
linkedin_user_id TEXT NOT NULL,
linkedin_vanity_name TEXT,
linkedin_name TEXT,
linkedin_picture TEXT,
-- OAuth Tokens (encrypted)
access_token TEXT NOT NULL,
refresh_token TEXT,
token_expires_at TIMESTAMP WITH TIME ZONE NOT NULL,
granted_scopes TEXT[] DEFAULT '{}',
-- Status
is_active BOOLEAN DEFAULT TRUE,
last_used_at TIMESTAMP WITH TIME ZONE,
last_error TEXT,
last_error_at TIMESTAMP WITH TIME ZONE,
UNIQUE(user_id) -- Only one account per user
);
CREATE INDEX idx_linkedin_accounts_user_id ON linkedin_accounts(user_id);
-- Enable RLS
ALTER TABLE linkedin_accounts ENABLE ROW LEVEL SECURITY;
-- Policy: Users can only see their own LinkedIn account
CREATE POLICY "Users can view own linkedin account"
ON linkedin_accounts FOR SELECT
USING (auth.uid() = user_id);
-- Policy: Users can insert their own LinkedIn account
CREATE POLICY "Users can insert own linkedin account"
ON linkedin_accounts FOR INSERT
WITH CHECK (auth.uid() = user_id);
-- Policy: Users can update their own LinkedIn account
CREATE POLICY "Users can update own linkedin account"
ON linkedin_accounts FOR UPDATE
USING (auth.uid() = user_id);
-- Policy: Users can delete their own LinkedIn account
CREATE POLICY "Users can delete own linkedin account"
ON linkedin_accounts FOR DELETE
USING (auth.uid() = user_id);
-- Function to update updated_at timestamp
CREATE OR REPLACE FUNCTION update_linkedin_accounts_updated_at()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER update_linkedin_accounts_updated_at
BEFORE UPDATE ON linkedin_accounts
FOR EACH ROW
EXECUTE FUNCTION update_linkedin_accounts_updated_at();