Skip to content

Commit

Permalink
added craft seeding support
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmancuso committed Jun 8, 2018
1 parent c62f218 commit 3a150b2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
17 changes: 17 additions & 0 deletions masonite/commands/SeedCommand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from cleo import Command
import subprocess


class SeedCommand(Command):
"""
Create a seeder to seed a database.
seed
{table : Name of the table to seed}
"""

def handle(self):
table = self.argument('table').lower()
subprocess.call([
"orator make:seed {}_table_seeder -p databases/seeds".format(table),
], shell=True)
22 changes: 22 additions & 0 deletions masonite/commands/SeedRunCommand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from cleo import Command
import subprocess


class SeedRunCommand(Command):
"""
Create a seeder to seed a database.
seed:run
{table=None : Name of the table to seed}
"""

def handle(self):
table = self.argument('table').lower()
if not table == 'none':
seeder = '--seeder {}_table_seeder'.format(table.lower())
else:
seeder = ''

subprocess.call([
"orator db:seed -p databases/seeds -c config/database.py -f {}".format(seeder),
], shell=True)
8 changes: 0 additions & 8 deletions masonite/commands/ServeCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ class ServeCommand(Command):
"""

def handle(self):
# try:
# call([
# "waitress-serve", '--port', self.option('port'),
# "--host", self.option('host'), "wsgi:application"
# ])
# except Exception:
# self.line('')
# self.comment('Server aborted!')
if self.option('reload'):
self._run_with_reloader(extra_files=[".env"])

Expand Down
5 changes: 5 additions & 0 deletions masonite/providers/AppProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from masonite.commands.ProviderCommand import ProviderCommand
from masonite.commands.RoutesCommand import RoutesCommand
from masonite.commands.ServeCommand import ServeCommand
from masonite.commands.SeedCommand import SeedCommand
from masonite.commands.SeedRunCommand import SeedRunCommand
from masonite.commands.TinkerCommand import TinkerCommand
from masonite.commands.ViewCommand import ViewCommand
from masonite.exception_handler import ExceptionHandler
Expand Down Expand Up @@ -58,12 +60,15 @@ def register(self):
self.app.bind('MasoniteViewCommand', ViewCommand())
self.app.bind('MasoniteRoutesCommand', RoutesCommand())
self.app.bind('MasoniteServeCommand', ServeCommand())
self.app.bind('MasoniteSeedCommand', SeedCommand())
self.app.bind('MasoniteSeedRunCommand', SeedRunCommand())
self.app.bind('MasoniteTinkerCommand', TinkerCommand())

self._autoload(application.AUTOLOAD)

def boot(self, Environ, Request, Route):
self.app.bind('Headers', [])
self.app.bind('StatusCode', '404 Not Found')
Route.load_environ(Environ)
Request.load_environ(Environ).load_app(self.app)

Expand Down

0 comments on commit 3a150b2

Please sign in to comment.