general: console cleanup
This commit is contained in:
@@ -8,7 +8,7 @@ import { v4 as uuidV4 } from "uuid";
|
||||
|
||||
export async function migrateMultiAuth() {
|
||||
const conn = ConnectionFactory();
|
||||
console.log("[Migration] Starting multi-auth migration...");
|
||||
|
||||
|
||||
try {
|
||||
// Step 1: Check if UserProvider table exists
|
||||
@@ -17,11 +17,9 @@ export async function migrateMultiAuth() {
|
||||
});
|
||||
|
||||
if (tableCheck.rows.length > 0) {
|
||||
console.log(
|
||||
"[Migration] UserProvider table already exists, skipping creation"
|
||||
);
|
||||
|
||||
} else {
|
||||
console.log("[Migration] Creating UserProvider table...");
|
||||
|
||||
await conn.execute(`
|
||||
CREATE TABLE UserProvider (
|
||||
id TEXT PRIMARY KEY,
|
||||
@@ -37,7 +35,7 @@ export async function migrateMultiAuth() {
|
||||
)
|
||||
`);
|
||||
|
||||
console.log("[Migration] Creating UserProvider indexes...");
|
||||
|
||||
await conn.execute(
|
||||
"CREATE UNIQUE INDEX IF NOT EXISTS idx_user_provider_provider_user ON UserProvider (provider, provider_user_id)"
|
||||
);
|
||||
@@ -64,11 +62,9 @@ export async function migrateMultiAuth() {
|
||||
);
|
||||
|
||||
if (hasDeviceName) {
|
||||
console.log(
|
||||
"[Migration] Session table already has device columns, skipping"
|
||||
);
|
||||
|
||||
} else {
|
||||
console.log("[Migration] Adding device columns to Session table...");
|
||||
|
||||
await conn.execute("ALTER TABLE Session ADD COLUMN device_name TEXT");
|
||||
await conn.execute("ALTER TABLE Session ADD COLUMN device_type TEXT");
|
||||
await conn.execute("ALTER TABLE Session ADD COLUMN browser TEXT");
|
||||
@@ -79,14 +75,12 @@ export async function migrateMultiAuth() {
|
||||
await conn.execute("ALTER TABLE Session ADD COLUMN last_active_at TEXT");
|
||||
|
||||
// Update existing rows to set last_active_at = last_used
|
||||
console.log(
|
||||
"[Migration] Updating existing sessions with last_active_at..."
|
||||
);
|
||||
|
||||
await conn.execute(
|
||||
"UPDATE Session SET last_active_at = COALESCE(last_used, created_at) WHERE last_active_at IS NULL"
|
||||
);
|
||||
|
||||
console.log("[Migration] Creating Session indexes...");
|
||||
|
||||
await conn.execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_session_last_active ON Session (last_active_at)"
|
||||
);
|
||||
@@ -96,14 +90,12 @@ export async function migrateMultiAuth() {
|
||||
}
|
||||
|
||||
// Step 3: Migrate existing users to UserProvider table
|
||||
console.log("[Migration] Checking for users to migrate...");
|
||||
|
||||
const usersResult = await conn.execute({
|
||||
sql: "SELECT id, email, provider, display_name, image, apple_user_string FROM User WHERE provider IS NOT NULL"
|
||||
});
|
||||
|
||||
console.log(
|
||||
`[Migration] Found ${usersResult.rows.length} users to migrate`
|
||||
);
|
||||
|
||||
|
||||
let migratedCount = 0;
|
||||
for (const row of usersResult.rows) {
|
||||
@@ -111,9 +103,7 @@ export async function migrateMultiAuth() {
|
||||
|
||||
// Skip apple provider users (they're for Life and Lineage mobile app, not website auth)
|
||||
if (user.provider === "apple") {
|
||||
console.log(
|
||||
`[Migration] Skipping user ${user.id} with apple provider (mobile app only)`
|
||||
);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -124,9 +114,7 @@ export async function migrateMultiAuth() {
|
||||
});
|
||||
|
||||
if (existingProvider.rows.length > 0) {
|
||||
console.log(
|
||||
`[Migration] User ${user.id} already migrated, skipping`
|
||||
);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -198,34 +186,30 @@ export async function migrateMultiAuth() {
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`[Migration] Migrated ${migratedCount} users successfully`);
|
||||
|
||||
|
||||
// Step 4: Verification
|
||||
console.log("[Migration] Running verification queries...");
|
||||
|
||||
const providerCount = await conn.execute({
|
||||
sql: "SELECT COUNT(*) as count FROM UserProvider"
|
||||
});
|
||||
console.log(
|
||||
`[Migration] Total providers in UserProvider table: ${(providerCount.rows[0] as any).count}`
|
||||
);
|
||||
|
||||
|
||||
const multiProviderUsers = await conn.execute({
|
||||
sql: `SELECT COUNT(*) as count FROM (
|
||||
SELECT user_id FROM UserProvider GROUP BY user_id HAVING COUNT(*) > 1
|
||||
)`
|
||||
});
|
||||
console.log(
|
||||
`[Migration] Users with multiple providers: ${(multiProviderUsers.rows[0] as any).count}`
|
||||
);
|
||||
|
||||
console.log("[Migration] Multi-auth migration completed successfully!");
|
||||
|
||||
|
||||
return {
|
||||
success: true,
|
||||
migratedUsers: migratedCount,
|
||||
totalProviders: (providerCount.rows[0] as any).count
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("[Migration] Migration failed:", error);
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -234,11 +218,11 @@ export async function migrateMultiAuth() {
|
||||
if (require.main === module) {
|
||||
migrateMultiAuth()
|
||||
.then((result) => {
|
||||
console.log("[Migration] Result:", result);
|
||||
|
||||
process.exit(0);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("[Migration] Error:", error);
|
||||
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user