Database initialization and migration #16
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Depends on
#6 Persistence module (database interaction)
Miroslavsckaya/tg_rss_bot
Reference: Miroslavsckaya/tg_rss_bot#16
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
We need to have database the code which will:
I propose to add several methods for the database wrapper class:
__initialize()
. It's called each time database wrapper is created (from the constructor). In case of SQLite it can create the file if needed and initialize the driver. Then it tries to get current version from the database using__get_current_version
. Then it calls__migrate(version)
whereversion
is the current version from the database (orNone
?).__migrate()
. Depending on the version it calls several blocks of statements consequentially to upgrade the database schema. If the current version is1
, it executes only statements for versions2
and above if they're present.__get_current_version()
. It goes tomigrations
table and selects the latest version.Simple example of
migrations
table:Selecting current version:
Each time database changes are made during the development, new version should be added to the code so other team members could automatically get their database migrated to the latest version.
An example of
__migrate()
implementation:Library options:
And even interesting external language-agnostic tool: