mirror of
https://github.com/KazooTTT/kazoottt-blog.git
synced 2025-06-17 07:51:22 +08:00
feat: add page view log
This commit is contained in:
34
scripts/deploy-db.cjs
Normal file
34
scripts/deploy-db.cjs
Normal file
@ -0,0 +1,34 @@
|
||||
require('dotenv').config();
|
||||
const { execSync } = require('child_process');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
// Check for required environment variable
|
||||
if (!process.env.CLOUDFLARE_API_TOKEN) {
|
||||
console.error('❌ CLOUDFLARE_API_TOKEN environment variable is required');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Get all SQL files from migrations directory
|
||||
const migrationsDir = path.join(__dirname, '..', 'migrations');
|
||||
const migrations = fs.readdirSync(migrationsDir)
|
||||
.filter(file => file.endsWith('.sql'))
|
||||
.sort(); // Sort to ensure consistent order
|
||||
|
||||
console.log('Found migrations:', migrations);
|
||||
|
||||
// Execute each migration
|
||||
migrations.forEach(migration => {
|
||||
const migrationPath = path.join('migrations', migration);
|
||||
console.log(`\nExecuting migration: ${migration}`);
|
||||
|
||||
try {
|
||||
execSync(`wrangler d1 execute blog-pageviews --file=./${migrationPath} --remote`, {
|
||||
stdio: 'inherit'
|
||||
});
|
||||
console.log(`✅ Successfully executed ${migration}`);
|
||||
} catch (error) {
|
||||
console.error(`❌ Failed to execute ${migration}`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user