db seed command
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -144,4 +144,4 @@ cython_debug/
|
|||||||
|
|
||||||
# End of https://www.toptal.com/developers/gitignore/api/python
|
# End of https://www.toptal.com/developers/gitignore/api/python
|
||||||
|
|
||||||
dev.db
|
*.db
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ def register_shellcontext(app: Flask):
|
|||||||
"""Shell context objects."""
|
"""Shell context objects."""
|
||||||
return {
|
return {
|
||||||
'db': db,
|
'db': db,
|
||||||
|
'TargetExchange': target_exchange.models.TargetExchange
|
||||||
}
|
}
|
||||||
|
|
||||||
app.shell_context_processor(shell_context)
|
app.shell_context_processor(shell_context)
|
||||||
@@ -63,3 +64,4 @@ def register_commands(app: Flask):
|
|||||||
"""Register Click commands."""
|
"""Register Click commands."""
|
||||||
app.cli.add_command(commands.clean)
|
app.cli.add_command(commands.clean)
|
||||||
app.cli.add_command(commands.urls)
|
app.cli.add_command(commands.urls)
|
||||||
|
app.cli.add_command(commands.seed)
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ from flask import current_app
|
|||||||
from flask.cli import with_appcontext
|
from flask.cli import with_appcontext
|
||||||
from werkzeug.exceptions import MethodNotAllowed, NotFound
|
from werkzeug.exceptions import MethodNotAllowed, NotFound
|
||||||
|
|
||||||
|
from .target_exchange.models import TargetExchange
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
def clean():
|
def clean():
|
||||||
"""Remove *.pyc and *.pyo files recursively starting at current directory.
|
"""Remove *.pyc and *.pyo files recursively starting at current directory.
|
||||||
@@ -79,3 +81,11 @@ def urls(url, order):
|
|||||||
|
|
||||||
for row in rows:
|
for row in rows:
|
||||||
click.echo(str_template.format(*row[:column_length]))
|
click.echo(str_template.format(*row[:column_length]))
|
||||||
|
|
||||||
|
@click.command()
|
||||||
|
@with_appcontext
|
||||||
|
def seed():
|
||||||
|
"""Seed the database"""
|
||||||
|
|
||||||
|
TargetExchange.ensure_created("")
|
||||||
|
TargetExchange.ensure_created("webhooks")
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
"""exchange management"""
|
"""exchange management"""
|
||||||
|
|
||||||
from . import views
|
from . import views, models
|
||||||
|
|||||||
@@ -6,5 +6,7 @@ class TargetExchange(SurrogatePK, Model):
|
|||||||
__tablename__ = "target-exchange"
|
__tablename__ = "target-exchange"
|
||||||
name = Column(db.String(255), unique=True, nullable=False)
|
name = Column(db.String(255), unique=True, nullable=False)
|
||||||
|
|
||||||
def __init__(self, name, **kwargs) -> None:
|
@staticmethod
|
||||||
Model.__init__(self, name=name, **kwargs)
|
def ensure_created(name):
|
||||||
|
if TargetExchange.query.filter_by(name=name).first() is None:
|
||||||
|
TargetExchange(name=name).save()
|
||||||
|
|||||||
Reference in New Issue
Block a user