Example #1
0
    def build_commands(self):

        files_database = database_parser(self.config['files_directory'])

        # any errors or warnings?
        quit_early = False
        if files_database.errors and not self.options['force']:
            print('Errors found in *.sql files', file=sys.stderr)
            quit_early = True
            for error in files_database.errors:
                print(error, file=sys.stderr)

        # or 1215 errors?
        if files_database.errors_1215 and not self.options['force']:
            print('1215 errors encountered', sys.stderr)
            quit_early = True
            for error in files_database.errors_1215:
                print(error, file=sys.stderr)

        if quit_early:
            return []

        # use the credentials to load up a database connection
        live_database = database_reader(mysqldb(self.credentials))

        # we have to tell the live database to load records
        # for any tables we are tracking records for.
        # We use the "files" database as the "truth" because
        # just about any database can have records, but
        # that doesn't mean we want to track them.  We only
        # track them if the file has rows.
        for table in files_database.tables.values():
            if not table.tracking_rows:
                continue

            if not table.name in live_database.tables:
                continue

            live_database.read_rows(table)

        mygrate = mygration(files_database, live_database, False)

        ops = []
        if mygrate.operations:
            ops.extend(mygrate.operations)

        rows = row_mygration(files_database, live_database)
        if rows.operations:
            ops.extend(rows.operations)

        if not ops:
            return []

        return [
            disable_checks(),
            *ops,
            enable_checks(),
        ]
    def execute(self):
        files_database = database_parser(self.config['files_directory'])

        # any errors or warnings?
        errors = False
        if files_database.errors:
            print('Errors found in *.sql files')
            errors = True
            for error in files_database.errors:
                print(error)

        errors_1215 = files_database.errors_1215
        if errors_1215:
            print('1215 Errors encountered')
            errors = True
            for error in errors_1215:
                print(error)

        if not errors:
            print("No problems found")
    def execute(self):

        files_database = database_parser(self.config['files_directory'])

        # use the credentials to load up a database connection
        live_database = database_reader(mysqldb(self.credentials))

        # we aren't outputting operations.  Instead we just need to know what tables
        # have changed (either structure or records).  The easiest (and slightly hack)
        # way to do that is to simply run an actual mygration and grab out the names
        # of the tables that have changed.  Cheating, I know
        self.modified_tables = {}
        mygrate = mygration(live_database, files_database, False)
        if mygrate.operations:
            for op in mygrate.operations:
                self.modified_tables[op.table_name] = True

        # we have to tell the live database to load records
        # for any tables we are tracking records for, according
        # to the files database.
        for table in files_database.tables.values():
            if not table.tracking_rows:
                continue
            if not table.name in live_database.tables:
                continue
            live_database.read_rows(table)

        rows = row_mygration(live_database, files_database)
        if rows.operations:
            for op in rows.operations:
                self.modified_tables[op.table_name] = True

        for table_name in self.modified_tables.keys():
            print('\033[1;33m\033[41m%s\033[0m' % table_name)
            table = live_database.tables[table_name]
            print(table.nice())

            if table.tracking_rows:
                print('\n')
                for row in table.rows.values():
                    print(row_insert(table.name, row))
Example #4
0
    def execute( self ):

        files_database = database_parser( self.config['files_directory'] )

        # any errors or warnings?
        if files_database.errors:
            print( 'Errors found in *.sql files' )
            for error in files_database.errors:
                print( error )

            return False

        # use the credentials to load up a database connection
        live_database = database_reader( mysqldb( self.credentials ) )

        # we have to tell the live database to load records
        # for any tables we are tracking records for.
        # We use the "files" database as the "truth" because
        # just about any database can have records, but
        # that doesn't mean we want to track them.  We only
        # track them if the file has rows.
        for table in files_database.tables.values():
            if not table.tracking_rows:
                continue

            if not table.name in live_database.tables:
                continue

            live_database.read_rows( table )

        mygrate = mygration( files_database, live_database )
        if mygrate.errors_1215:
            print( '1215 Errors encountered' )
            for error in mygrate.errors_1215:
                print( error )

        else:
            for op in mygrate.operations:
                live_database.apply_to_source( op )