-
Notifications
You must be signed in to change notification settings - Fork 2
/
firmware_update.py
47 lines (40 loc) · 2.17 KB
/
firmware_update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""Xiaomi Firmware Updater Database Update model"""
from sqlalchemy import Column, INT, VARCHAR, CHAR, BIGINT, DATE, TIMESTAMP, ForeignKeyConstraint, Table, TEXT
from sqlalchemy.sql.functions import current_timestamp
from . import Base
class Update(Base):
"""
Update class that represents a device update
"""
__tablename__ = 'firmware'
id: int = Column(INT(), primary_key=True, autoincrement=True)
codename: str = Column(VARCHAR(30), nullable=False)
version: str = Column(VARCHAR(20), nullable=False)
android: str = Column(VARCHAR(5), nullable=False)
branch: str = Column(VARCHAR(15), nullable=False)
size: str = Column(BIGINT(), nullable=True)
md5: str = Column(CHAR(32), unique=True, nullable=True)
filename: str = Column(TEXT(), unique=True, nullable=True)
github_link: str = Column(TEXT(), nullable=False)
osdn_link: str = Column(TEXT(), nullable=True)
date: str = Column(DATE(), nullable=True)
inserted_on: str = Column(TIMESTAMP(), default=current_timestamp())
def __repr__(self):
return f"<Update(codename={self.codename}, version={self.version}, branch={self.branch})>"
def __str__(self):
return str({k: v for k, v in self.__dict__.items() if not k.startswith("_")})
def get_table(metadata):
return Table('firmware', metadata,
Column('id', INT(), primary_key=True, autoincrement=True),
Column('codename', VARCHAR(30), nullable=False),
Column('version', VARCHAR(20), nullable=False),
Column('android', VARCHAR(5), nullable=False),
Column('branch', VARCHAR(15), nullable=False),
Column('size', BIGINT(), nullable=True),
Column('md5', CHAR(32), nullable=True, unique=True),
Column('filename', TEXT(), nullable=False, unique=True),
Column('github_link', TEXT(), nullable=False),
Column('osdn_link', TEXT(), nullable=True),
Column('date', DATE(), nullable=True),
Column('inserted_on', TIMESTAMP(), default=current_timestamp()),
ForeignKeyConstraint(['codename'], ['devices.codename'], use_alter=True))