File size: 1,537 Bytes
23abae1 ed43d03 23abae1 ed43d03 23abae1 ed43d03 23abae1 ed43d03 23abae1 ed43d03 23abae1 ed43d03 23abae1 ed43d03 23abae1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
const admin = require('firebase-admin');
const { Client } = require('pg');
async function sync() {
try {
console.log("🚀 Strategic Sync Starting...");
const serviceAccount = JSON.parse(process.env.FIREBASE_SERVICE_ACCOUNT);
admin.initializeApp({ credential: admin.credential.cert(serviceAccount) });
const db = admin.firestore();
const client = new Client({
connectionString: process.env.NEON_DATABASE_URL,
ssl: { rejectUnauthorized: false }
});
await client.connect();
console.log("✅ Neon Connected!");
// Table ရှိမရှိစစ်ပြီး မရှိရင် ဇွတ်ဆောက်မယ်
await client.query(`
CREATE TABLE IF NOT EXISTS neurons (
id SERIAL PRIMARY KEY,
data JSONB NOT NULL,
evolved_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
`);
const snap = await db.collection('neurons').limit(5).get();
for (const doc of snap.docs) {
// Colab မှာတွေ့တဲ့ evolved_at column ထဲကို ဇွတ်ထည့်မယ်
await client.query('INSERT INTO neurons (data, evolved_at) VALUES ($1, NOW())', [JSON.stringify(doc.data())]);
}
console.log("🏁 SUCCESS: Mission Accomplished!");
await client.end();
} catch (err) {
console.error("❌ ERROR:", err.message);
process.exit(1);
}
}
sync();
|