<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-

from entity import configuration as config_entity
from entity import tag as tag_entity
from migration import tags as tag_lists

import os
import shutil
import sqlite3
import sys

class MigrationManager:
    """ Checks current version and migrates if necessary.

    Constants:
    CONFIG_VERSION -- The version name in configuration table (string).
    EMPTY_DB_FILE -- Name of empty database file (string).

    Member:
    home -- The home directory (string).
    db_file -- Path to sqlite database file.
    """

    CONFIG_VERSION = 'version'
    EMPTY_DB_FILE = 'empty-db.sqlite'

    def __init__(self, home, db_file):
        self.home = home
        self.db_file = home+db_file

    def migrate(self):
        """ Executes checks and migrates if necessary. Sub functions should
        always commit changes in the database. """
        # Version 1
        self.__create_db()
        db = sqlite3.connect(self.db_file)

        # Version 1 -> 2
        current = 1
        if self.__is_version(db, current):
            self.__create_tags(db, tag_lists.tags_001)
            current += 1
            self.__update_version(db, current)

        # Version 2 -> 3
        if self.__is_version(db, current):
            self.__tags_rename_vermouth(db)
            current += 1
            self.__update_version(db, current)

        # Version 3 -> 4
        if self.__is_version(db, current):
            self.__tags_rename_brackets(db)
            current += 1
            self.__update_version(db, current)
            
        # Version 4 -> 5
        if self.__is_version(db, current):
            self.__create_tags(db, tag_lists.tags_002)
            current += 1
            self.__update_version(db, current)<commit_msg>Migration should even work if db already existed.<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-

from entity import configuration as config_entity
from entity import tag as tag_entity
from migration import tags as tag_lists

import os
import shutil
import sqlite3
import sys

class MigrationManager:
    """ Checks current version and migrates if necessary.

    Constants:
    CONFIG_VERSION -- The version name in configuration table (string).
    EMPTY_DB_FILE -- Name of empty database file (string).

    Member:
    home -- The home directory (string).
    db_file -- Path to sqlite database file.
    """

    CONFIG_VERSION = 'version'
    EMPTY_DB_FILE = 'empty-db.sqlite'

    def __init__(self, home, db_file):
        self.home = home
        self.db_file = home+db_file

    def migrate(self):
        """ Executes checks and migrates if necessary. Sub functions should
        always commit changes in the database. """
        # Version 1
        self.__create_db()
        db = sqlite3.connect(self.db_file)

        # Version 1 -> 2
        current = 1
        if self.__is_version(db, current):
            self.__create_tags(db, tag_lists.tags_001)
            current += 1
            self.__update_version(db, current)

        # Version 2 -> 3
        current = 2
        if self.__is_version(db, current):
            self.__tags_rename_vermouth(db)
            current += 1
            self.__update_version(db, current)

        # Version 3 -> 4
        current = 3
        if self.__is_version(db, current):
            self.__tags_rename_brackets(db)
            current += 1
            self.__update_version(db, current)
            
        # Version 4 -> 5
        current = 4
        if self.__is_version(db, current):
            self.__create_tags(db, tag_lists.tags_002)
            current += 1
            self.__update_version(db, current)

        # Version 5 -> 6
        current = 5
{'fraction_non_alphanumeric': 0.08597528210639441, 'fraction_numerical': 0.013970983342289092, 'mean_word_length': 2.0870646766169156, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3372567', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1014, 'n_words': 313}