Add Note Sharing feature.
This commit is contained in:
21
migrations/add_note_sharing.sql
Normal file
21
migrations/add_note_sharing.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
-- Add note_share table for public note sharing functionality
|
||||
CREATE TABLE IF NOT EXISTS note_share (
|
||||
id SERIAL PRIMARY KEY,
|
||||
note_id INTEGER NOT NULL REFERENCES note(id) ON DELETE CASCADE,
|
||||
token VARCHAR(64) UNIQUE NOT NULL,
|
||||
expires_at TIMESTAMP,
|
||||
password_hash VARCHAR(255),
|
||||
view_count INTEGER DEFAULT 0,
|
||||
max_views INTEGER,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
created_by_id INTEGER NOT NULL REFERENCES "user"(id),
|
||||
last_accessed_at TIMESTAMP
|
||||
);
|
||||
|
||||
-- Create indexes for better performance
|
||||
CREATE INDEX IF NOT EXISTS idx_note_share_token ON note_share(token);
|
||||
CREATE INDEX IF NOT EXISTS idx_note_share_note_id ON note_share(note_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_note_share_created_by ON note_share(created_by_id);
|
||||
|
||||
-- Add comment
|
||||
COMMENT ON TABLE note_share IS 'Public sharing links for notes with optional password protection and view limits';
|
||||
@@ -17,6 +17,7 @@ MIGRATION_STATE_FILE = '/data/postgres_migrations_state.json'
|
||||
# List of PostgreSQL migrations in order
|
||||
POSTGRES_MIGRATIONS = [
|
||||
'postgres_only_migration.py', # Main migration from commit 4214e88 onward
|
||||
'add_note_sharing.sql', # Add note sharing functionality
|
||||
]
|
||||
|
||||
|
||||
@@ -49,12 +50,27 @@ def run_migration(migration_file):
|
||||
print(f"\n🔄 Running migration: {migration_file}")
|
||||
|
||||
try:
|
||||
# Run the migration script
|
||||
result = subprocess.run(
|
||||
[sys.executable, script_path],
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
# Check if it's a SQL file
|
||||
if migration_file.endswith('.sql'):
|
||||
# Run SQL file using psql
|
||||
import os
|
||||
db_host = os.environ.get('POSTGRES_HOST', 'db')
|
||||
db_name = os.environ.get('POSTGRES_DB', 'timetrack')
|
||||
db_user = os.environ.get('POSTGRES_USER', 'timetrack')
|
||||
|
||||
result = subprocess.run(
|
||||
['psql', '-h', db_host, '-U', db_user, '-d', db_name, '-f', script_path],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
env={**os.environ, 'PGPASSWORD': os.environ.get('POSTGRES_PASSWORD', 'timetrack')}
|
||||
)
|
||||
else:
|
||||
# Run Python migration script
|
||||
result = subprocess.run(
|
||||
[sys.executable, script_path],
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
|
||||
if result.returncode == 0:
|
||||
print(f"✅ {migration_file} completed successfully")
|
||||
|
||||
Reference in New Issue
Block a user