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.

Add database migration script

See original GitHub issue

We’ve had the issue a couple of times where a new release breaks compatibility with the database format while not really changing much. The way this is handled in other libraries is by providing a migration script that works like this:

$ terracotta migrate mysql://
Found Terracotta database v0.7.3 (this is v0.8.0)
Bump database to v0.8.0? (y/N)
Performing database migration ...

$ terracotta migrate mysql://
Found Terracotta database v0.0.1 (this is v0.8.0)
Error: cannot auto-migrate. Please re-create database.

$ terracotta migrate mysql://
Found Terracotta database v0.8.1 (this is v0.8.0)
Nothing to do

This requires some sort of incremental changelog that specifies the necessary transformations between versions.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

nickeopticommented, Aug 15, 2022

I hope to get time to help at some point. Until then, this can probably get you started:

We can actually use the driver logic, just set verify=False to disable all checks:

import sqlalchemy as sqla
from terracotta import drivers

driver = drivers.get_driver('<driver_path>')
with driver.connect(verify=False):
    driver.meta_store.connection.execute(sqla.text('<raw sql statement>'))
dionhaefnercommented, Aug 11, 2022

Okay so I played around with alembic and … didn’t love it.

The biggest problem (apart from the steep learning curve) is that modifying SQLite is not fully supported (for example re-naming tables which just ends in NotImplementedError).

I’m hesitant whether we need a migration library at all. Some simple ALTER TABLE statements should do it. I suggest we use SQLalchemy to connect to the DB, then run the migration via engine.execute and raw SQL.

@nickeopti could you perhaps imagine writing the SQLalchemy boilerplate for this? 😬 Then I can finish up the actual migrations and CLI and such.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Migration Scripts in Database Deployments - Simple Talk
A SQL migration script is similar to a SQL build script, except that it changes a database from one version to another, rather...
Read more >
Code First Migrations - EF6 - Microsoft Learn
We want a script to go from an empty database ($InitialDatabase) to the latest version (migration AddPostAbstract). If you don't specify a ...
Read more >
Database Migration — Writing Scripts & Best Practices - Medium
Manual Migration Script — this is a script written by a database programmer. Sometimes it is impossible for a tool to create a...
Read more >
Code-Based Migration in Entity Framework 6
Update-Database: Executes the last migration file created by the Add-Migration command and applies changes to the database schema.
Read more >
Migration scripts introduction and general review
The main purpose of using the migration scripts is to ensure that database changes, being made and committed to source control, can be...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found