<commit_before>package org.stepic.droid.storage.migration

import android.database.sqlite.SQLiteDatabase
import org.stepik.android.cache.assignment.structure.DbStructureAssignment
import org.stepik.android.cache.step.structure.DbStructureStep

object MigrationFrom40To41 : Migration {
    override fun migrate(db: SQLiteDatabase) {
        createStepsTable(db)
        migrateSteps(db)

        createAssignmentsTable(db)
        migrateAssignments(db)
    }

    private fun createStepsTable(db: SQLiteDatabase) {
        db.execSQL("""
            CREATE TABLE IF NOT EXISTS ${DbStructureStep.TABLE_NAME} (
                ${DbStructureStep.Column.ID} LONG PRIMARY KEY,
                ${DbStructureStep.Column.LESSON_ID} LONG,
                ${DbStructureStep.Column.POSITION} INTEGER,

                ${DbStructureStep.Column.STATUS} TEXT,
                ${DbStructureStep.Column.PROGRESS} TEXT,
                ${DbStructureStep.Column.SUBSCRIPTION} TEXT,

                ${DbStructureStep.Column.VIEWED_BY} LONG,
                ${DbStructureStep.Column.PASSED_BY} LONG,
                ${DbStructureStep.Column.WORTH} LONG,

                ${DbStructureStep.Column.CREATE_DATE} LONG,
                ${DbStructureStep.Column.UPDATE_DATE} LONG,

                ${DbStructureStep.Column.DISCUSSION_COUNT} INTEGER,
                ${DbStructureStep.Column.DISCUSSION_PROXY} TEXT,

                ${DbStructureStep.Column.PEER_REVIEW} TEXT,
                ${DbStructureStep.Column.HAS_SUBMISSION_RESTRICTION} BOOLEAN,
                ${DbStructureStep.Column.MAX_SUBMISSION_COUNT} INTEGER
            )
        """.trimIndent())
    }

    private fun migrateSteps(db: SQLiteDatabase) {
        db.execSQL("""
            REPLACE INTO ${DbStructureStep.TABLE_NAME}
            SELECT
                ${org.stepic.droid.storage.structure.DbStructureStep.Column.STEP_ID},
                ${org.stepic.droid.storage.structure.DbStructureStep.Column.LESSON_ID},
                ${org.stepic.droid.storage.structure.DbStructureStep.Column.POSITION},

                ${org.stepic.droid.storage.structure.DbStructureStep.Column.STATUS},
                ${org.stepic.droid.storage.structure.DbStructureStep.Column.PROGRESS},
                ${org.stepic.droid.storage.structure.DbStructureStep.Column.SUBSCRIPTIONS},

                ${org.stepic.droid.storage.structure.DbStructureStep.Column.VIEWED_BY},
                ${org.stepic.droid.storage.structure.DbStructureStep.Column.PASSED_BY},
                0,
                -1,
                -1,
                ${org.stepic.droid.storage.structure.DbStructureStep.Column.DISCUSSION_COUNT},
                ${org.stepic.droid.storage.structure.DbStructureStep.Column.DISCUSSION_ID},
                ${org.stepic.droid.storage.structure.DbStructureStep.Column.PEER_REVIEW},
                ${org.stepic.droid.storage.structure.DbStructureStep.Column.HAS_SUBMISSION_RESTRICTION},
                ${org.stepic.droid.storage.structure.DbStructureStep.Column.MAX_SUBMISSION_COUNT}
            FROM ${org.stepic.droid.storage.structure.DbStructureStep.STEPS}
        """.trimIndent())
    }

    private fun createAssignmentsTable(db: SQLiteDatabase) {
        db.execSQL("""
             CREATE TABLE IF NOT EXISTS ${DbStructureAssignment.TABLE_NAME} (
                ${DbStructureAssignment.Columns.ID} LONG PRIMARY KEY,
                ${DbStructureAssignment.Columns.STEP} LONG,
                ${DbStructureAssignment.Columns.UNIT} LONG,

                ${DbStructureAssignment.Columns.PROGRESS} TEXT,

                ${DbStructureStep.Column.CREATE_DATE} LONG,
                ${DbStructureStep.Column.UPDATE_DATE} LONG
            )
        """.trimIndent())
    }

    private fun migrateAssignments(db: SQLiteDatabase) {
        db.execSQL("""
            REPLACE INTO ${DbStructureAssignment.TABLE_NAME}
            SELECT
                ${org.stepic.droid.storage.structure.DbStructureAssignment.Column.ASSIGNMENT_ID},
                ${org.stepic.droid.storage.structure.DbStructureAssignment.Column.STEP_ID},
                ${org.stepic.droid.storage.structure.DbStructureAssignment.Column.UNIT_ID},
                ${org.stepic.droid.storage.structure.DbStructureAssignment.Column.PROGRESS},
                -1,
                -1
            FROM ${org.stepic.droid.storage.structure.DbStructureStep.STEPS}
        """.trimIndent())
    }
}<commit_msg>fix migration source<commit_after>package org.stepic.droid.storage.migration

import android.database.sqlite.SQLiteDatabase
import org.stepik.android.cache.assignment.structure.DbStructureAssignment
import org.stepik.android.cache.step.structure.DbStructureStep

object MigrationFrom40To41 : Migration {
    override fun migrate(db: SQLiteDatabase) {
        createStepsTable(db)
        migrateSteps(db)

        createAssignmentsTable(db)
        migrateAssignments(db)
    }

    private fun createStepsTable(db: SQLiteDatabase) {
        db.execSQL("""
            CREATE TABLE IF NOT EXISTS ${DbStructureStep.TABLE_NAME} (
                ${DbStructureStep.Column.ID} LONG PRIMARY KEY,
                ${DbStructureStep.Column.LESSON_ID} LONG,
                ${DbStructureStep.Column.POSITION} INTEGER,

                ${DbStructureStep.Column.STATUS} TEXT,
                ${DbStructureStep.Column.PROGRESS} TEXT,
                ${DbStructureStep.Column.SUBSCRIPTION} TEXT,

                ${DbStructureStep.Column.VIEWED_BY} LONG,
                ${DbStructureStep.Column.PASSED_BY} LONG,
                ${DbStructureStep.Column.WORTH} LONG,

                ${DbStructureStep.Column.CREATE_DATE} LONG,
                ${DbStructureStep.Column.UPDATE_DATE} LONG,

                ${DbStructureStep.Column.DISCUSSION_COUNT} INTEGER,
                ${DbStructureStep.Column.DISCUSSION_PROXY} TEXT,

                ${DbStructureStep.Column.PEER_REVIEW} TEXT,
                ${DbStructureStep.Column.HAS_SUBMISSION_RESTRICTION} BOOLEAN,
                ${DbStructureStep.Column.MAX_SUBMISSION_COUNT} INTEGER
            )
        """.trimIndent())
    }

    private fun migrateSteps(db: SQLiteDatabase) {
        db.execSQL("""
            REPLACE INTO ${DbStructureStep.TABLE_NAME}
            SELECT
                ${org.stepic.droid.storage.structure.DbStructureStep.Column.STEP_ID},
                ${org.stepic.droid.storage.structure.DbStructureStep.Column.LESSON_ID},
                ${org.stepic.droid.storage.structure.DbStructureStep.Column.POSITION},

                ${org.stepic.droid.storage.structure.DbStructureStep.Column.STATUS},
                ${org.stepic.droid.storage.structure.DbStructureStep.Column.PROGRESS},
                ${org.stepic.droid.storage.structure.DbStructureStep.Column.SUBSCRIPTIONS},

                ${org.stepic.droid.storage.structure.DbStructureStep.Column.VIEWED_BY},
                ${org.stepic.droid.storage.structure.DbStructureStep.Column.PASSED_BY},
                0,
                -1,
                -1,
                ${org.stepic.droid.storage.structure.DbStructureStep.Column.DISCUSSION_COUNT},
                ${org.stepic.droid.storage.structure.DbStructureStep.Column.DISCUSSION_ID},
                ${org.stepic.droid.storage.structure.DbStructureStep.Column.PEER_REVIEW},
                ${org.stepic.droid.storage.structure.DbStructureStep.Column.HAS_SUBMISSION_RESTRICTION},
                ${org.stepic.droid.storage.structure.DbStructureStep.Column.MAX_SUBMISSION_COUNT}
            FROM ${org.stepic.droid.storage.structure.DbStructureStep.STEPS}
        """.trimIndent())
    }

    private fun createAssignmentsTable(db: SQLiteDatabase) {
        db.execSQL("""
             CREATE TABLE IF NOT EXISTS ${DbStructureAssignment.TABLE_NAME} (
                ${DbStructureAssignment.Columns.ID} LONG PRIMARY KEY,
                ${DbStructureAssignment.Columns.STEP} LONG,
                ${DbStructureAssignment.Columns.UNIT} LONG,

                ${DbStructureAssignment.Columns.PROGRESS} TEXT,

                ${DbStructureStep.Column.CREATE_DATE} LONG,
                ${DbStructureStep.Column.UPDATE_DATE} LONG
            )
        """.trimIndent())
    }

    private fun migrateAssignments(db: SQLiteDatabase) {
        db.execSQL("""
            REPLACE INTO ${DbStructureAssignment.TABLE_NAME}
            SELECT
                ${org.stepic.droid.storage.structure.DbStructureAssignment.Column.ASSIGNMENT_ID},
                ${org.stepic.droid.storage.structure.DbStructureAssignment.Column.STEP_ID},
                ${org.stepic.droid.storage.structure.DbStructureAssignment.Column.UNIT_ID},
                ${org.stepic.droid.storage.structure.DbStructureAssignment.Column.PROGRESS},
                -1,
                -1
            FROM ${org.stepic.droid.storage.structure.DbStructureAssignment.ASSIGNMENTS}
        """.trimIndent())
    }
}
{'fraction_non_alphanumeric': 0.10548856080243435, 'fraction_numerical': 0.0020286261692775837, 'mean_word_length': 2.3074916138650763, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3837565', 'n_tokens_mistral': 2638, 'n_tokens_neox': 2453, 'n_words': 276}