diff options
| author | Matt Arnold | 2025-04-16 04:34:39 -0400 | 
|---|---|---|
| committer | Matt Arnold | 2025-04-16 04:34:39 -0400 | 
| commit | 86b3c15595708df0593109ca4cefbc7e05acb371 (patch) | |
| tree | 4ffe95e82de7181766a268c9f996d734a2c4e49f | |
| parent | 6e1f614f0cf67d997c0a1b7e4e3866294c05f1e0 (diff) | |
Add installer script to init the database from zero,.
Make profile picture nullable field
| -rwxr-xr-x | migrate.py | 50 | ||||
| -rw-r--r-- | models.py | 8 | 
2 files changed, 56 insertions, 2 deletions
| diff --git a/migrate.py b/migrate.py new file mode 100755 index 0000000..c386a0e --- /dev/null +++ b/migrate.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python +from getpass import getpass +import click +from models import User as NewUser +from models import Faccet, Post +from models import db as database +from models import generate_password_hash + + +first_post = """ +# Welcome to vibes + +Vibes is journaling based forum software. Built for intentional communities and people. +Have fun and be safe +""" +post_subject = "Welcome" +bio_default = "They've been chilling in the basement for a minute" + + +@click.group() +def cli(): +    pass + + +@cli.command +def install(): +    database.create_tables([NewUser, Post, Faccet]) + +    username = click.prompt("Enter a user account name:", default="user", type=str) +    profile_name = click.prompt("Enter a profile name:", default="enzo", type=str) +    usr = None +    passwd = getpass(f"Enter password for {username}: ") +    confirm = getpass("Confirm: ") +    if passwd != confirm: +        click.echo("password mismatch") +        return 1 +    hashed = generate_password_hash(passwd) +    with database: +        usr = NewUser.create( +            username=username, default_faccet=profile_name, password_hash=hashed +        ) +        profile = Faccet.create(user_belongs=usr, name=profile_name, bio=bio_default) +        Post.create(authour=profile, parent=0, title=post_subject, content=first_post) + +    styled = click.style("It worked boot up the app", bold=True, fg="green") +    click.echo(styled) + + +if __name__ == "__main__": +    cli() @@ -30,7 +30,7 @@ class User(UserMixin, BaseModel):  class Faccet(BaseModel):      user_belongs = ForeignKeyField(User, backref="parts")      name = TextField(unique=True) -    picture = BlobField() +    picture = BlobField(null=True)      bio = TextField()      birth = DateTimeField(default=datetime.now) @@ -65,7 +65,11 @@ def get_attribed_posts(uid):  def get_tview(post_id): -    return Post.select().where(Post.parent == post_id).order_by(Post.id.asc()) +    return ( +        Post.select() +        .where((Post.parent == post_id) | (Post.id == post_id)) +        .order_by(Post.id.asc()) +    )  db.create_tables([User, Post, Faccet]) | 
