-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎉 Create migration file for onboarding table
- Loading branch information
1 parent
0634aaf
commit 027e665
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2024-07-30_11-02-04.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# | ||
# CREATED ON VERSION: V4.1.1 | ||
# MIGRATION: 2024-07-30_11-02-04 | ||
# CREATED: Tue Jul 30 2024 | ||
# | ||
|
||
from peewee import * | ||
from playhouse.migrate import * | ||
|
||
from app import db | ||
|
||
# Do not change the name of this file, | ||
# migrations are run in order of their filenames date and time | ||
|
||
def run(): | ||
# Use migrator to perform actions on the database | ||
migrator = SqliteMigrator(db) | ||
|
||
# Create new table 'onboarding' | ||
with db.transaction(): | ||
# Check if the table exists | ||
cursor = db.cursor() | ||
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='onboarding';") | ||
table_exists = cursor.fetchone() | ||
|
||
if not table_exists: | ||
db.execute_sql(""" | ||
CREATE TABLE "onboarding" ( | ||
"id" INTEGER NOT NULL UNIQUE, | ||
"value" TEXT NOT NULL, | ||
"order" INTEGER NOT NULL UNIQUE, | ||
"enabled" INTEGER NOT NULL DEFAULT 1, | ||
PRIMARY KEY("id") | ||
) | ||
""") | ||
print("Table 'onboarding' created successfully") | ||
else: | ||
print("Table 'onboarding' already exists") | ||
|
||
print("Migration 2024-07-30_11-02-04 complete") |