85 lines
1.8 KiB
Python
85 lines
1.8 KiB
Python
from lapp import create_app
|
|
from models import db
|
|
from models import Group, Item, ListOfItems, Shared, User
|
|
|
|
|
|
def print_section(title):
|
|
print()
|
|
print("=" * len(title))
|
|
print(title)
|
|
print("=" * len(title))
|
|
|
|
|
|
def print_model_rows(model, columns):
|
|
primary_key = next(iter(model.__table__.primary_key.columns))
|
|
rows = model.query.order_by(primary_key).all()
|
|
if not rows:
|
|
print("(empty)")
|
|
return
|
|
|
|
for row in rows:
|
|
values = []
|
|
for column in columns:
|
|
values.append(f"{column}={getattr(row, column)!r}")
|
|
print(", ".join(values))
|
|
|
|
|
|
def main():
|
|
app = create_app()
|
|
with app.app_context():
|
|
print(f"Database: {app.config['SQLALCHEMY_DATABASE_URI']}")
|
|
|
|
print_section("Users")
|
|
print_model_rows(User, [
|
|
"id",
|
|
"updated_at",
|
|
"group_id",
|
|
"name",
|
|
"password_hash",
|
|
"is_admin",
|
|
"is_approved",
|
|
"is_private",
|
|
"is_guest",
|
|
])
|
|
|
|
print_section("Groups")
|
|
print_model_rows(Group, [
|
|
"id",
|
|
"updated_at",
|
|
"secret",
|
|
])
|
|
|
|
print_section("Lists")
|
|
print_model_rows(ListOfItems, [
|
|
"id",
|
|
"updated_at",
|
|
"owner_user_id",
|
|
"name",
|
|
"is_active",
|
|
])
|
|
|
|
print_section("Items")
|
|
print_model_rows(Item, [
|
|
"id",
|
|
"updated_at",
|
|
"listofitems_id",
|
|
"label",
|
|
"quantity",
|
|
"unit",
|
|
"label_alt1",
|
|
"label_alt2",
|
|
"is_checked",
|
|
"is_suggestion",
|
|
"category",
|
|
])
|
|
|
|
print_section("Shares")
|
|
print_model_rows(Shared, [
|
|
"user_id",
|
|
"listofitem_id",
|
|
])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|