Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ __pycache__
node_modules
.mypy_cache
.venv
.pytest_cache
data
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"short_description": "Receive payments for products offline!",
"tile": "/offlineshop/static/image/offlineshop.png",
"version": "1.1.1",
"min_lnbits_version": "1.3.0",
"min_lnbits_version": "1.4.1",
"contributors": [
{
"name": "fiatjaf",
Expand Down
42 changes: 14 additions & 28 deletions migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ async def m001_initial(db):
"""
Initial offlineshop tables.
"""
await db.execute(
f"""
await db.execute(f"""
CREATE TABLE offlineshop.shops (
id {db.serial_primary_key},
wallet TEXT NOT NULL,
method TEXT NOT NULL,
wordlist TEXT
);
"""
)
""")

await db.execute(
f"""
await db.execute(f"""
CREATE TABLE offlineshop.items (
shop INTEGER NOT NULL REFERENCES {db.references_schema}shops (id),
id {db.serial_primary_key},
Expand All @@ -25,20 +22,17 @@ async def m001_initial(db):
price {db.big_int} NOT NULL,
unit TEXT NOT NULL DEFAULT 'sat'
);
"""
)
""")


async def m002_fiat_base_multiplier(db):
"""
Store the multiplier for fiat prices. We store the price in cents and
remember to multiply by 100 when we use it to convert to Dollars.
"""
await db.execute(
"""
await db.execute("""
ALTER TABLE offlineshop.items ADD COLUMN fiat_base_multiplier INTEGER DEFAULT 1
"""
)
""")


async def m003_id_as_text(db):
Expand All @@ -47,28 +41,23 @@ async def m003_id_as_text(db):
"""
# Shops
await db.execute("ALTER TABLE offlineshop.shops RENAME TO old_shop;")
await db.execute(
"""
await db.execute("""
CREATE TABLE offlineshop.shops (
id TEXT PRIMARY KEY,
wallet TEXT NOT NULL,
method TEXT NOT NULL,
wordlist TEXT
);
"""
)
await db.execute(
"""
""")
await db.execute("""
INSERT INTO offlineshop.shops (id, wallet, method, wordlist)
SELECT id, wallet, method, wordlist FROM offlineshop.old_shop;
"""
)
""")

# Items
await db.execute("UPDATE offlineshop.items SET unit = 'sats' WHERE unit = 'sat';")
await db.execute("ALTER TABLE offlineshop.items RENAME TO old_item;")
await db.execute(
"""
await db.execute("""
CREATE TABLE offlineshop.items (
shop TEXT NOT NULL,
id TEXT PRIMARY KEY,
Expand All @@ -79,16 +68,13 @@ async def m003_id_as_text(db):
price REAL NOT NULL,
unit TEXT NOT NULL DEFAULT 'sats'
);
"""
)
await db.execute(
"""
""")
await db.execute("""
INSERT INTO offlineshop.items
(shop, id, name, description, image, enabled, price, unit)
SELECT shop, id, name, description, image, enabled, price, unit FROM
offlineshop.old_item;
"""
)
""")
await db.execute(
"UPDATE offlineshop.items SET price = price / 100 WHERE unit != 'sats';"
)
Expand Down
Loading
Loading