Files
cloudlense/website-monitoring-frontend/deploy-schema.js
T
Dennis 14a32bdc0d feat: initialize monorepo with full dev team best practices
- Unified monorepo with backend (Express), frontend (Next.js), and devops
- Backend: ESLint, Prettier, Jest tests (3 passing), health endpoint, .env.example
- Frontend: Fixed build errors, fixed all lint errors (0 remaining), tests passing
- DevOps: Docker Compose with PostgreSQL, backend, frontend + healthchecks
- CI/CD: 3 GitHub Actions workflows (backend, frontend, docker integration)
- DX: Husky pre-commit hooks with smart change detection
- Docs: Root README with architecture, CONTRIBUTING.md, PR template

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-06 00:05:50 +01:00

68 lines
1.9 KiB
JavaScript

const fs = require('fs');
const { createClient } = require('@supabase/supabase-js');
// Read environment variables
require('dotenv').config();
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
const serviceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY;
if (!supabaseUrl || !serviceRoleKey) {
console.error('Missing required environment variables');
process.exit(1);
}
const supabase = createClient(supabaseUrl, serviceRoleKey, {
auth: {
autoRefreshToken: false,
persistSession: false
}
});
async function deploySchema() {
try {
console.log('🚀 Starting database schema deployment...');
// Read the SQL file
const sqlContent = fs.readFileSync('supabase-fixes.sql', 'utf8');
// Split the SQL into individual statements
const statements = sqlContent
.split(';')
.map(stmt => stmt.trim())
.filter(stmt => stmt.length > 0 && !stmt.startsWith('--'));
console.log(`📝 Found ${statements.length} SQL statements to execute`);
// Execute each statement
for (let i = 0; i < statements.length; i++) {
const statement = statements[i];
if (statement.trim()) {
console.log(`⚡ Executing statement ${i + 1}/${statements.length}...`);
try {
const { data, error } = await supabase.rpc('exec_sql', {
sql: statement + ';'
});
if (error) {
console.warn(`⚠️ Warning on statement ${i + 1}:`, error.message);
} else {
console.log(`✅ Statement ${i + 1} executed successfully`);
}
} catch (err) {
console.warn(`⚠️ Error on statement ${i + 1}:`, err.message);
}
}
}
console.log('🎉 Database schema deployment completed!');
} catch (error) {
console.error('❌ Error deploying schema:', error);
process.exit(1);
}
}
deploySchema();