db-manager: This is dangerous, change it
When db-manager
is asked to clobber the existing data, it does so by deleting all tables in the current schema in the current database.
if (clobber) {
logger.info('Overwriting existing database due to clobber option')
await Promise.all(
// TODO this is dangerous, change it
rows.map(row => db.query(`DROP TABLE ${row.tablename} CASCADE`)),
)
}
By default the current schema is public
and the current database is that of the current user. This has a high potential for accidentally deleting data that doesn't belong to PubSweet which the developer just happened to keep in their default local Postgres database.
Options
- Only delete tables created by pubsweet. This requires some way to determine which tables are pubsweet's
- Table name prefix (like wordpress does
wp_
) - Components export a list of their table names
- Table name prefix (like wordpress does
- Encourage users to create a dedicated database and warn that any other data stored in that database will be lost
- Remove the
clobber
option and put the responsibility on the user to clear the database
I think I favour option 2, possibly combined with option 3.