Exemplo n.º 1
0
    def __init__(self, connection=None):
        self._ran = []
        self._notes = []
        from config import database
        database_dict = database.DB

        self.repository = DatabaseMigrationRepository(database.DB,
                                                      'migrations')
        self.migrator = Migrator(self.repository, database.DB)
        if not connection or connection == 'default':
            connection = database.DATABASES['default']
        self.migrator.set_connection(connection)
        if not self.repository.repository_exists():
            self.repository.create_repository()

        from wsgi import container

        self.migration_directories = ['databases/migrations']
        for key, value in container.providers.items():
            if isinstance(key, str) and 'MigrationDirectory' in key:
                self.migration_directories.append(value)

        try:
            add_venv_site_packages()
        except ImportError:
            self.comment(
                'This command must be ran inside of the root of a Masonite project directory'
            )
Exemplo n.º 2
0
    def handle(self):
        sys.path.append(os.getcwd())
        try:
            add_venv_site_packages()
        except ImportError:
            self.comment(
                'This command must be ran inside of the root of a Masonite project directory')

        from wsgi import container

        migration_directory = ['databases/migrations']
        for key, value in container.providers.items():
            if type(key) == str and 'MigrationDirectory' in key:
                migration_directory.append(value)

        for directory in migration_directory:
            self.line('')
            if len(migration_directory) > 1:
                self.info('Migrate Status: {}'.format(directory))
            try:
                output = bytes(check_output(
                    ['orator', 'migrate:status', '-c',
                        'config/database.py', '-p', directory]
                )).decode('utf-8')

                self.line(
                    output.replace('Yes', '<info>Yes</info>')
                    .replace('No', '<comment>No</comment>'))
            except Exception:
                pass
Exemplo n.º 3
0
    def handle(self):
        sys.path.append(os.getcwd())
        try:
            add_venv_site_packages()
        except ImportError:
            self.comment('This command must be ran inside of the root of a Masonite project directory')

        from wsgi import container

        migration_directory = ['databases/migrations']
        for key, value in container.providers.items():
            if 'MigrationDirectory' in key:
                migration_directory.append(value)

        for directory in migration_directory:
            self.line('')
            if len(migration_directory) > 1:
                self.info('Migrating: {0}'.format(directory))
            try:
                output = bytes(check_output(
                        ['orator', 'migrate', '-c', 'config/database.py', '-p', directory, '-f']
                    )).decode('utf-8')

                self.line(
                    output.replace('OK', '<info>OK</info>') \
                    .replace('Migrated', '<info>Migrated</info><fg=cyan>') + '</>'
                )
            except Exception:
                pass
    def handle(self):
        sys.path.append(os.getcwd())
        try:
            add_venv_site_packages()
            from wsgi import container
        except ImportError:
            self.comment(
                'This command must be ran inside of the root of a Masonite project directory'
            )

        # Get any migration files from the Service Container
        migration_directory = ['databases/migrations']
        for key, value in container.providers.items():
            if 'MigrationDirectory' in key:
                migration_directory.append(value)

        # Load in the Orator migration system
        from orator.migrations import Migrator, DatabaseMigrationRepository
        from config import database
        repository = DatabaseMigrationRepository(database.DB, 'migrations')
        migrator = Migrator(repository, database.DB)
        if not migrator.repository_exists():
            repository.create_repository()

        # Create a new list of migrations with the correct file path instead
        migration_list = []
        for migration in migrator.get_repository().get_ran():
            for directory in migration_directory:
                if os.path.exists(os.path.join(directory, migration + '.py')):
                    migration_list.append(os.path.join(os.getcwd(), directory))
                    break

        # Rollback the migrations
        notes = []
        for migration in migrator.get_repository().get_ran():
            for migration_directory in migration_list:
                try:
                    migrator.reset(migration_directory)
                except QueryException as e:
                    raise e
                except FileNotFoundError:
                    pass

                if migrator.get_notes():
                    notes += migrator.get_notes()

        # Show notes from the migrator
        self.line('')
        for note in notes:
            if not ('Nothing to rollback.' in note):
                self.line(note)
        if not notes:
            self.info('Nothing to rollback')