Skip to content

Commit e8a22ee

Browse files
authored
fix: add migration 006 detection to pre-Alembic stamping logic (#63)
Databases created by create_all() (SQLite) include all v6.2.0 schema (forum_topics table, is_forum column, etc.) but no alembic_version. On restart, the stamping logic only detected up to 005, so it stamped at 005 and tried to run migration 006 which failed with "duplicate column name: is_forum". Fix: Add forum_topics table detection for migration 006 in both the SQLite and PostgreSQL stamping paths. Bump to v6.2.2.
1 parent c55566c commit e8a22ee

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "telegram-archive"
7-
version = "6.2.1"
7+
version = "6.2.2"
88
description = "Automated Telegram backup with Docker. Performs incremental backups of messages and media on a configurable schedule."
99
readme = "README.md"
1010
requires-python = ">=3.11"

scripts/entrypoint.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ if has_tables and not has_alembic:
8181
CONSTRAINT alembic_version_pkc PRIMARY KEY (version_num)
8282
);
8383
\"\"\")
84+
# Check if forum_topics table exists (added in migration 006)
85+
cur.execute(\"\"\"
86+
SELECT EXISTS (
87+
SELECT FROM information_schema.tables
88+
WHERE table_name = 'forum_topics'
89+
);
90+
\"\"\")
91+
has_006_table = cur.fetchone()[0]
92+
8493
# Check if idx_messages_reply_to index exists (added in migration 005)
8594
cur.execute(\"\"\"
8695
SELECT EXISTS (
@@ -109,7 +118,9 @@ if has_tables and not has_alembic:
109118
has_push_subs = cur.fetchone()[0]
110119
111120
# Determine which version to stamp based on existing schema
112-
if has_005_index:
121+
if has_006_table:
122+
stamp_version = '006'
123+
elif has_005_index:
113124
stamp_version = '005'
114125
elif has_is_pinned:
115126
stamp_version = '004'
@@ -168,6 +179,10 @@ if has_tables and not has_alembic:
168179
)
169180
''')
170181
182+
# Check if forum_topics table exists (added in migration 006)
183+
cur.execute(\"SELECT name FROM sqlite_master WHERE type='table' AND name='forum_topics'\")
184+
has_006_table = cur.fetchone() is not None
185+
171186
# Check for idx_messages_reply_to index (added in migration 005)
172187
cur.execute(\"SELECT name FROM sqlite_master WHERE type='index' AND name='idx_messages_reply_to'\")
173188
has_005_index = cur.fetchone() is not None
@@ -182,7 +197,9 @@ if has_tables and not has_alembic:
182197
has_push_subs = cur.fetchone() is not None
183198
184199
# Determine which version to stamp based on existing schema
185-
if has_005_index:
200+
if has_006_table:
201+
stamp_version = '006'
202+
elif has_005_index:
186203
stamp_version = '005'
187204
elif has_is_pinned:
188205
stamp_version = '004'

0 commit comments

Comments
 (0)