Working tree is now the canonical repo. Off-chain play-money + trustless on-chain (FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution, mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
87 lines
2.1 KiB
TypeScript
87 lines
2.1 KiB
TypeScript
import { runScript } from 'run-script'
|
|
import { type SupabaseDirectClient } from 'shared/supabase/init'
|
|
import * as fs from 'fs'
|
|
import { parse } from 'csv-parse/sync'
|
|
|
|
// Upload data from CSV files generated by dump-lovers.ts to the database
|
|
runScript(async ({ pg }) => {
|
|
try {
|
|
await uploadUsers(pg)
|
|
await uploadChats(pg)
|
|
console.log('Migration completed successfully')
|
|
} catch (error) {
|
|
console.error('Migration failed:', error)
|
|
process.exit(1)
|
|
}
|
|
})
|
|
|
|
const uploadUsers = async (pg: SupabaseDirectClient) => {
|
|
const fileContent = fs.readFileSync('users.csv', 'utf-8')
|
|
const records = parse(fileContent, {
|
|
columns: true,
|
|
skip_empty_lines: true,
|
|
cast: true // Automatically convert strings to appropriate types
|
|
})
|
|
|
|
// Create temp table with same structure
|
|
await pg.none(`
|
|
CREATE TEMP TABLE temp_users (
|
|
id text,
|
|
username text,
|
|
name text,
|
|
user_data jsonb,
|
|
private_user_data jsonb
|
|
)
|
|
`)
|
|
|
|
// Bulk insert into temp table
|
|
const cs = new pg.helpers.ColumnSet([
|
|
'id',
|
|
'username',
|
|
'name',
|
|
{ name: 'user_data', mod: ':json' },
|
|
{ name: 'private_user_data', mod: ':json' }
|
|
], { table: 'temp_users' })
|
|
|
|
const query = pg.helpers.insert(records, cs)
|
|
await pg.none(query)
|
|
|
|
console.log(`Uploaded ${records.length} users`)
|
|
}
|
|
|
|
const uploadChats = async (pg: SupabaseDirectClient) => {
|
|
const fileContent = fs.readFileSync('chats.csv', 'utf-8')
|
|
const records = parse(fileContent, {
|
|
columns: true,
|
|
skip_empty_lines: true,
|
|
cast: true
|
|
})
|
|
|
|
// Create temp table matching private_user_messages structure
|
|
await pg.none(`
|
|
CREATE TEMP TABLE temp_messages (
|
|
id bigint,
|
|
channel_id bigint,
|
|
user_id text,
|
|
content jsonb,
|
|
created_time timestamp with time zone,
|
|
visibility text
|
|
)
|
|
`)
|
|
|
|
// Bulk insert into temp table
|
|
const cs = new pg.helpers.ColumnSet([
|
|
'id',
|
|
'channel_id',
|
|
'user_id',
|
|
{ name: 'content', mod: ':json' },
|
|
'created_time',
|
|
'visibility'
|
|
], { table: 'temp_messages' })
|
|
|
|
const query = pg.helpers.insert(records, cs)
|
|
await pg.none(query)
|
|
|
|
console.log(`Uploaded ${records.length} messages`)
|
|
}
|