Skip to content

Commit 101b78f

Browse files
committed
Add --db-list option to list available databases
1 parent 42da439 commit 101b78f

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

scripts/lib.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ Options:
2020
Creates meteor/.meteor/local/db.<name> and switches to it with a symlink
2121
Original database is backed up to db.default on first use
2222
Run without --db to use the currently active database
23+
--db-list List all available database directories and show which is active
2324
2425
Examples:
2526
yarn start # Install, build, then run in dev mode
2627
yarn dev # Run in normal dev mode (requires prior build)
28+
yarn dev --db-list # List all available databases
2729
yarn dev --db=testing # Use a separate database for testing
2830
yarn dev --db=demo # Switch to demo database
2931
yarn dev --ui-only # Only watch UI, skip backend packages
@@ -42,6 +44,7 @@ const config = {
4244
inspectMeteor: args.indexOf("--inspect-meteor") >= 0 || false,
4345
verbose: args.indexOf("--verbose") >= 0 || false,
4446
dbName: dbName,
47+
dbList: args.indexOf("--db-list") >= 0 || false,
4548
};
4649

4750
module.exports = {

scripts/run.mjs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,52 @@ function hr() {
7272
return "─".repeat(process.stdout.columns ?? 40);
7373
}
7474

75+
function listDatabases() {
76+
const meteorLocalDir = path.join('meteor', '.meteor', 'local');
77+
const dbLink = path.join(meteorLocalDir, 'db');
78+
79+
if (!fs.existsSync(meteorLocalDir)) {
80+
console.log('No databases found (meteor/.meteor/local does not exist yet)');
81+
return;
82+
}
83+
84+
// Get current database
85+
let currentDb = null;
86+
if (fs.existsSync(dbLink)) {
87+
const stats = fs.lstatSync(dbLink);
88+
if (stats.isSymbolicLink()) {
89+
const target = fs.readlinkSync(dbLink);
90+
const match = target.match(/^db\.(.+)$/);
91+
if (match) {
92+
currentDb = match[1];
93+
}
94+
} else {
95+
currentDb = '(unnamed - real directory)';
96+
}
97+
}
98+
99+
// List all db.* directories
100+
const files = fs.readdirSync(meteorLocalDir);
101+
const dbDirs = files
102+
.filter(file => file.startsWith('db.') && fs.statSync(path.join(meteorLocalDir, file)).isDirectory())
103+
.map(file => file.substring(3));
104+
105+
console.log('\nAvailable databases:');
106+
if (dbDirs.length === 0) {
107+
console.log(' (none found)');
108+
} else {
109+
dbDirs.sort().forEach(db => {
110+
const marker = db === currentDb ? ' ← current' : '';
111+
console.log(` ${db}${marker}`);
112+
});
113+
}
114+
115+
if (currentDb && !dbDirs.includes(currentDb)) {
116+
console.log(`\nCurrent: ${currentDb}`);
117+
}
118+
console.log('');
119+
}
120+
75121
function switchDatabase(dbName) {
76122
const meteorLocalDir = path.join('meteor', '.meteor', 'local');
77123
const dbLink = path.join(meteorLocalDir, 'db');
@@ -118,6 +164,12 @@ function switchDatabase(dbName) {
118164
try {
119165
// Note: This script assumes that install-and-build.mjs has been run before
120166

167+
// List databases if requested
168+
if (config.dbList) {
169+
listDatabases();
170+
process.exit(0);
171+
}
172+
121173
// Switch database if requested
122174
if (config.dbName) {
123175
switchDatabase(config.dbName);

0 commit comments

Comments
 (0)