question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: It should be possible to use the SQLite database based on a file

See original GitHub issue

Feature Suggestion

The Backstage example app in this repository uses an in-memory SQLite database. This means that if the user changes the state of the database, and restarts the backend, all the changes disappear. This eventually becomes a source of confusion for Backstage contributors.

If the default SQLite connection were based on filesystem, instead of in-memory, the data will persist. And it will still be lightweight than PostgreSQL.

We already discourage the use of example app in production, hence this change does not increase the risk of people using SQLite in production.

It should be possible to switch the in-memory SQLite config to one that is based on a file.

Possible Implementation

Discovering this PR https://github.com/backstage/backstage/pull/5308 from @Fox32, looks like it’s possible to update the app-config.yaml to

backend:
  database:
    client: sqlite3
    connection:
      filename: 'backstage-db.sqlite'

and start using filesystem based SQLite connection!

But unfortunately this does not work for me and throws a “migrations directory is corrupt” error.

Backend failed to start up Error: The migration directory is corrupt, the following files are missing: 20200511113813_init.js, 20200520140700_location_update_log_table.js, 20200527114117_location_update_log_latest_view.js, 20200702153613_entities.js, 20200721115244_location_update_log_latest_deduplicate.js, 20200805163904_location_update_log_duplication_fix.js, 20200807120600_entitySearch.js, 20200809202832_add_bootstrap_location.js, 20200923104503_case_insensitivity.js, 20201005122705_add_entity_full_name.js, 20201006130744_entity_data_column.js, 20201006203131_entity_remove_redundant_columns.js, 20201007201501_index_entity_search.js, 20201019130742_add_relations_table.js, 20201123205611_relations_table_uniq.js, 20201210185851_fk_index.js, 20201230103504_update_log_varchar.js, 20210209121210_locations_fk_index.js, 20210302150147_refresh_state.js, 20210622104022_refresh_state_location_key.js
    at validateMigrationList (/Users/himanshum/workspace/github.com/backstage/backstage/node_modules/knex/lib/migrations/migrate/Migrator.js:575:11)
    at Migrator.latest (/Users/himanshum/workspace/github.com/backstage/backstage/node_modules/knex/lib/migrations/migrate/Migrator.js:70:7)
    at async Function.create (webpack-internal:///../../plugins/scaffolder-backend/src/scaffolder/tasks/DatabaseTaskStore.ts:70:5)
    at async createRouter (webpack-internal:///../../plugins/scaffolder-backend/src/service/router.ts:95:29)
    at async createPlugin (webpack-internal:///./src/plugins/scaffolder.ts:46:10)
    at async main (webpack-internal:///./src/index.ts:121:32)

Context

Why the default should be in-memory SQLite database which does not persist across sessions?

(I don’t have any strong reasons here to be honest. Please comment!)

  • A nudge for people to switch to PostgreSQL so that they don’t accidentally deploy sqlite database.
  • Speed?

Why the default should be a file based sqlite database, which persists across sessions?

  1. No surprise loss of data for new Backstage integrators.

This has been a constant source of confusion on Discord for new people. Quoting @Pike here (in a call with @adamopenweb) - I was told to use SQLite for my new Backstage app saying it’s safe now and easy to switch later. I lost my populated catalog eventually - so it wasn’t safe.

  1. Authentication signing key gets lost, forcing user to sign out and sign in for token verification to work every time

While working with verifying a Backstage token in the backend, we found out that a signing key is created by the auth-backend plugin when the first user signs in and the key is stored in the database. After restarting the backend, the user is still logged in, but there is no signing key available in the database. This means the backstage token can no longer be verified without the user signing out and signing in again. This dramatically increases the debugging cycle.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ckt114commented, Sep 29, 2022

This works if I set backend.database.connection.directory: /abs/path/to/sqlite/db/folder.

1reaction
OrkoHuntercommented, Aug 18, 2021

Makes sense to me @Rugvip - I’ll re-purpose the issue!

I think we could save some people by adding just a warning log in backend saying that the database used is in-memory and will be cleaned when the backend starts.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Appropriate Uses For SQLite
Because an SQLite database requires no administration, it works well in devices that must operate without expert human support.
Read more >
sqlite3.OperationalError: unable to open database file
PROBLEM You're using SQLite3, your DATABASE_NAME is set to the database file's full path, the database file is writeable by Apache, but you ......
Read more >
The SQLite Magellan Bug, And Your App - CommonsWare
It may be possible for an attacker to exploit this bug just using a SQLite database file that you open and attempt to...
Read more >
Why do I get sqlite error, "unable to open database file"?
The solution is to make sure the directory containing the database file also has write access allowed to the process. In my case,...
Read more >
SQLite Python: Creating a New Database
When you connect to an SQLite database file that does not exist, SQLite automatically creates the new database for you. To create a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found