summary refs log tree commit diff
path: root/migrate.py
blob: c386a0ebe8c09ec8d5b522290c94c5aa83543af8 (plain)
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
48
49
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()