Skip to content

Commit 1af17ac

Browse files
committed
rm: emojis
1 parent b012488 commit 1af17ac

7 files changed

Lines changed: 53 additions & 58 deletions

File tree

src/cli.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ async function chooseDatabase() {
1414
const dbConnections = getDbConnectionsFromEnv();
1515

1616
if (dbConnections.size === 0) {
17-
console.log(" No database connection found in the .env file.");
17+
console.log("Error: No database connection found in the .env file.");
1818
process.exit(1);
1919
}
2020

@@ -32,12 +32,12 @@ async function chooseDatabase() {
3232

3333
const dbUrl = dbConnections.get(selectedDb);
3434
if (!dbUrl) {
35-
console.error("Error: Invalid connection string.");
35+
console.error("Error: Invalid connection string.");
3636
process.exit(1);
3737
}
3838

3939
const db = database(dbUrl);
40-
console.log(`Connected to database: ${selectedDb}`);
40+
console.log(`Connected to database: ${selectedDb}`);
4141
return { selectedDb, db };
4242
}
4343

@@ -49,16 +49,16 @@ async function main() {
4949
{
5050
type: "list",
5151
name: "action",
52-
message: "📋 What do you want to do?",
52+
message: "What do you want to do?",
5353
choices: [
54-
{ name: "📤 Dump the database to a SQL file", value: "dump" },
55-
{ name: "📜 Export schema to a SQL file", value: "schema" },
56-
{ name: "🧨 Drop all tables (DROP)", value: "drop" },
57-
{ name: "🧹 Truncate all data (TRUNCATE)", value: "truncate" },
58-
{ name: "📊 List tables with their size", value: "list" },
59-
{ name: "📥 Import an existing SQL dump", value: "import" },
60-
{ name: "🔄 Change database", value: "changeDb" },
61-
{ name: "Exit", value: "exit" },
54+
{ name: "Dump the database to a SQL file", value: "dump" },
55+
{ name: "Export schema to a SQL file", value: "schema" },
56+
{ name: "Drop all tables (DROP)", value: "drop" },
57+
{ name: "Truncate all data (TRUNCATE)", value: "truncate" },
58+
{ name: "List tables with their size", value: "list" },
59+
{ name: "Import an existing SQL dump", value: "import" },
60+
{ name: "Change database", value: "changeDb" },
61+
{ name: "Exit", value: "exit" },
6262
],
6363
},
6464
]);
@@ -93,14 +93,14 @@ async function main() {
9393
await importDump(db);
9494
break;
9595
case "changeDb":
96-
console.log("🔑 Choosing a new database...");
96+
console.log("Switching database...");
9797
({ selectedDb, db } = await chooseDatabase());
9898
break;
9999
default:
100100
process.exit(0);
101101
}
102102
} catch (err) {
103-
console.error("Fatal error:", err);
103+
console.error("Fatal error:", err);
104104
process.exit(1);
105105
}
106106
}

src/features/drop.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function topologicalSort(
7272
}
7373

7474
async function dropAllTypes(db: Kysely<Record<string, unknown>>) {
75-
console.log(chalk.gray("🧹 Removing custom types..."));
75+
console.log(chalk.gray("Removing custom types..."));
7676

7777
const types = await sql<{ typname: string }>`
7878
SELECT t.typname
@@ -90,7 +90,7 @@ async function dropAllTypes(db: Kysely<Record<string, unknown>>) {
9090
.execute(db);
9191
}
9292

93-
console.log(chalk.green("Custom types removed."));
93+
console.log(chalk.green("Custom types removed."));
9494
}
9595

9696
export async function dropAllTables(db: Kysely<Record<string, unknown>>) {
@@ -100,27 +100,27 @@ export async function dropAllTables(db: Kysely<Record<string, unknown>>) {
100100
try {
101101
const ordered = topologicalSort(tables, deps);
102102

103-
console.log("🧹 Removing tables in the correct order:");
103+
console.log("Removing tables in the correct order:");
104104
console.log(ordered.join(" → "));
105105

106106
for (const table of ordered) {
107107
await sql.raw(`DROP TABLE IF EXISTS "${table}" CASCADE`).execute(db);
108-
console.log(chalk.green(`Table "${table}" removed`));
108+
console.log(chalk.green(`Table "${table}" removed`));
109109
}
110110

111-
console.log(chalk.green("🎉 All tables have been properly removed."));
111+
console.log(chalk.green("All tables have been properly removed."));
112112
} catch (_e: unknown) {
113113
console.warn(
114-
chalk.yellow("⚠️ Cycle detected: forced removal (DROP CASCADE on all)"),
114+
chalk.yellow(
115+
"Warning: Cycle detected, forcing removal with CASCADE on all tables",
116+
),
115117
);
116118

117119
const tableList = tables.map((t) => `"${t}"`).join(", ");
118120
await sql.raw(`DROP TABLE IF EXISTS ${tableList} CASCADE`).execute(db);
119121

120122
console.log(
121-
chalk.green(
122-
"✅ All tables have been removed with CASCADE (order ignored).",
123-
),
123+
chalk.green("All tables have been removed with CASCADE (order ignored)."),
124124
);
125125
} finally {
126126
await dropAllTypes(db);

src/features/dump.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export async function dump(
140140
) {
141141
const tables = await getAllTableNames(db);
142142

143-
console.log(`📦 Found ${tables.length} tables to dump.`);
143+
console.log(`Found ${tables.length} tables to dump.`);
144144

145145
const sortedTables = await sortTablesByForeignKeys(tables, db);
146146

@@ -151,23 +151,23 @@ export async function dump(
151151
const sql = await generateInsertSQL(table, db);
152152
if (sql) {
153153
insertStatements.push(sql);
154-
console.log(`Dumped ${table}`);
154+
console.log(`Dumped ${table}`);
155155
} else {
156-
console.log(`⚠️ Skipped empty table ${table}`);
156+
console.log(`Skipped empty table ${table}`);
157157
}
158158
} catch (e) {
159-
console.error(`Failed to dump table "${table}":`, e);
159+
console.error(`Failed to dump table "${table}":`, e);
160160
}
161161
}
162162

163163
let schemaStatements: string[] = [];
164164
if (withSchema) {
165-
console.log("📐 Exporting schema...");
165+
console.log("Exporting schema...");
166166
schemaStatements = await generateSchemaStatements(db, sortedTables);
167167
}
168168

169169
// Get sequence reset statements
170-
console.log("📐 Preparing sequence reset statements...");
170+
console.log("Preparing sequence reset statements...");
171171
const sequenceResets = await getSequenceResetStatements(db, sortedTables);
172172

173173
const fullSQL = [
@@ -186,5 +186,5 @@ export async function dump(
186186
mkdirSync(path.dirname(OUTPUT_FILE), { recursive: true });
187187
writeFileSync(OUTPUT_FILE, fullSQL);
188188

189-
console.log(`🎉 Dump SQL generated at ${OUTPUT_FILE}`);
189+
console.log(`Dump SQL generated at ${OUTPUT_FILE}`);
190190
}

src/features/empty.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export async function truncateTables(db: Kysely<Record<string, unknown>>) {
1919
const tables = await getAllTableNames(db);
2020

2121
if (tables.length === 0) {
22-
console.log("ℹ️ No tables found in the public schema.");
22+
console.log("No tables found in the public schema.");
2323
return;
2424
}
2525

@@ -41,24 +41,24 @@ export async function truncateTables(db: Kysely<Record<string, unknown>>) {
4141
: (selectedTables as Array<string>);
4242

4343
if (tablesToTruncate.length === 0) {
44-
console.log("ℹ️ No table selected.");
44+
console.log("No table selected.");
4545
return;
4646
}
4747

4848
const tableList = tablesToTruncate.map((t) => `"${t}"`).join(", ");
4949

5050
try {
51-
console.log("🧨 Truncating tables (with CASCADE)...");
51+
console.log("Truncating tables (with CASCADE)...");
5252

5353
await sql
5454
.raw(`TRUNCATE TABLE ${tableList} RESTART IDENTITY CASCADE`)
5555
.execute(db);
5656

5757
console.log(
58-
`Tables ${tablesToTruncate.join(", ")} successfully truncated (including cycles & FK). \n`,
58+
`Tables ${tablesToTruncate.join(", ")} successfully truncated (including cycles & FK). \n`,
5959
);
6060
} catch (e) {
61-
console.error("Error during TRUNCATE:", e);
61+
console.error("Error during TRUNCATE:", e);
6262
process.exit(1);
6363
}
6464
}

src/features/import.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function importDump(db: Kysely<Record<string, unknown>>) {
3131
const dumps = await getAvailableDumps(BACKUPS_DIR);
3232

3333
if (dumps.length === 0) {
34-
console.log(chalk.red("No dump file found in the backups folder."));
34+
console.log(chalk.red("No dump file found in the backups folder."));
3535
return;
3636
}
3737

@@ -45,7 +45,7 @@ export async function importDump(db: Kysely<Record<string, unknown>>) {
4545
]);
4646

4747
const dumpPath = path.resolve(BACKUPS_DIR, selectedDump);
48-
console.log(chalk.gray(`📥 Importing file: ${dumpPath}...`));
48+
console.log(chalk.gray(`Importing file: ${dumpPath}...`));
4949

5050
const dumpContent = await fs.readFile(dumpPath, "utf8");
5151
const statements = dumpContent
@@ -58,14 +58,14 @@ export async function importDump(db: Kysely<Record<string, unknown>>) {
5858
try {
5959
await trx.executeQuery(sql.raw(stmt).compile(trx));
6060
} catch (err) {
61-
console.error(chalk.red(`Error at: ${stmt.slice(0, 80)}...`));
61+
console.error(chalk.red(`Error at: ${stmt.slice(0, 80)}...`));
6262
throw err;
6363
}
6464
}
6565
});
6666

67-
console.log(chalk.green("Dump successfully imported via Kysely."));
67+
console.log(chalk.green("Dump successfully imported !"));
6868
} catch (err) {
69-
console.error(chalk.red("Import failed:"), err);
69+
console.error(chalk.red("Import failed:"), err);
7070
}
7171
}

src/features/list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export async function listTablesWithSize(db: Kysely<Record<string, unknown>>) {
1515
ORDER BY pg_total_relation_size('"' || t.table_name || '"') DESC
1616
`.execute(db);
1717

18-
console.log(chalk.bold("\n📊 Tables in the public schema:\n"));
18+
console.log(chalk.bold("\nTables in the public schema:\n"));
1919

2020
if (result.rows.length === 0) {
2121
console.log(chalk.gray("No tables found."));

src/features/schema.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ interface SequenceDefinition {
4444
cycle: boolean;
4545
}
4646

47-
48-
4947
async function getSequences(
5048
db: Kysely<Record<string, unknown>>,
5149
): Promise<string[]> {
@@ -350,48 +348,45 @@ export async function generateSchemaStatements(
350348
db: Kysely<Record<string, unknown>>,
351349
tables: string[],
352350
): Promise<string[]> {
353-
console.log("📦 Exporting sequences...");
351+
console.log("Exporting sequences...");
354352
const sequences = await getSequences(db);
355353

356-
console.log("📦 Exporting custom types...");
354+
console.log("Exporting custom types...");
357355
const enumTypes = await getEnumTypes(db);
358356

359-
console.log("📦 Exporting tables...");
357+
console.log("Exporting tables...");
360358
const createTableStatements: string[] = [];
361359
for (const table of tables) {
362360
try {
363361
const createTableStatement = await getTableSchema(db, table);
364362
createTableStatements.push(createTableStatement);
365363
} catch (e) {
366-
console.error(`Failed to export schema for table "${table}":`, e);
364+
console.error(`Failed to export schema for table "${table}":`, e);
367365
}
368366
}
369367

370-
console.log("📦 Exporting sequence ownerships...");
368+
console.log("Exporting sequence ownerships...");
371369
const sequenceOwnerships = await getSequenceOwnerships(db);
372370

373-
console.log("📦 Exporting foreign keys...");
371+
console.log("Exporting foreign keys...");
374372
const foreignKeyStatements: string[] = [];
375373
for (const table of tables) {
376374
try {
377375
const fks = await getForeignKeys(db, table);
378376
foreignKeyStatements.push(...fks);
379377
} catch (e) {
380-
console.error(
381-
`❌ Failed to export foreign keys for table "${table}":`,
382-
e,
383-
);
378+
console.error(`Failed to export foreign keys for table "${table}":`, e);
384379
}
385380
}
386381

387-
console.log("📦 Exporting indexes...");
382+
console.log("Exporting indexes...");
388383
const indexStatements: string[] = [];
389384
for (const table of tables) {
390385
try {
391386
const indexes = await getIndexes(db, table);
392387
indexStatements.push(...indexes);
393388
} catch (e) {
394-
console.error(`Failed to export indexes for table "${table}":`, e);
389+
console.error(`Failed to export indexes for table "${table}":`, e);
395390
}
396391
}
397392

@@ -412,12 +407,12 @@ export async function exportSchema(
412407
dbName: string,
413408
) {
414409
const tables = await getAllTableNames(db);
415-
console.log(`📦 Found ${tables.length} tables to export schema for.`);
410+
console.log(`Found ${tables.length} tables to export schema for.`);
416411

417412
const statements = await generateSchemaStatements(db, tables);
418413

419414
for (const table of tables) {
420-
console.log(`Exported schema for table ${table}`);
415+
console.log(`Exported schema for table ${table}`);
421416
}
422417

423418
const fullSQL = statements.join("\n\n");
@@ -426,5 +421,5 @@ export async function exportSchema(
426421
mkdirSync(path.dirname(OUTPUT_FILE), { recursive: true });
427422
writeFileSync(OUTPUT_FILE, fullSQL);
428423

429-
console.log(`🎉 Schema SQL generated at ${OUTPUT_FILE}`);
424+
console.log(`Schema SQL generated at ${OUTPUT_FILE}`);
430425
}

0 commit comments

Comments
 (0)