<commit_before>"""
Django management command to load the lms_user_id column from historical data.
"""
from __future__ import absolute_import

import logging

from django.apps import apps
from django.core.management.base import BaseCommand
from django.db import connection, transaction
from django.db.models import Max

User = apps.get_model('core', 'User')
logger = logging.getLogger(__name__)


class Command(BaseCommand):
    help = """
    Import username/lms_user_id mappings into the lms_user_id column.

    Export data for this by running this query from the LMS:
        SELECT *
        INTO OUTFILE 'test_users.csv'
        FIELDS TERMINATED BY ','
        OPTIONALLY ENCLOSED BY '"'
        LINES TERMINATED BY '\n'
        FROM (
            SELECT
                username,
                id as user_id
            FROM auth_user
            WHERE id NOT IN (
                SELECT user_id FROM user_api_userretirementstatus
            )
            UNION SELECT
                original_username AS username,
                user_id
            FROM user_api_userretirementstatus
        ) u

    Import data into ecommerce using:

    CREATE TABLE temp_username_userid
    (
    username VARCHAR(150),
    lms_user_id INT(11),
    PRIMARY KEY(lms_user_id)
    )
    ENGINE = InnoDB;

    LOAD DATA FROM S3 FILE 's3-BUCKET_ID/username_userid'
    INTO TABLE temp_username_userid
    FIELDS TERMINATED BY ','
    OPTIONALLY ENCLOSED BY '"'
    LINES TERMINATED BY '\n'
        (username, lms_user_id)
    """

    def add_arguments(self, parser):
        parser.add_argument(
            '--max-user-id',
            type=int,
            default=None,
            help="Maximum user id to update"
        )
        parser.add_argument(<commit_msg>Add the index required to make import_user_ids performant<commit_after>"""
Django management command to load the lms_user_id column from historical data.
"""
from __future__ import absolute_import

import logging

from django.apps import apps
from django.core.management.base import BaseCommand
from django.db import connection, transaction
from django.db.models import Max

User = apps.get_model('core', 'User')
logger = logging.getLogger(__name__)


class Command(BaseCommand):
    help = """
    Import username/lms_user_id mappings into the lms_user_id column.

    Export data for this by running this query from the LMS:
        SELECT *
        INTO OUTFILE 'test_users.csv'
        FIELDS TERMINATED BY ','
        OPTIONALLY ENCLOSED BY '"'
        LINES TERMINATED BY '\n'
        FROM (
            SELECT
                username,
                id as user_id
            FROM auth_user
            WHERE id NOT IN (
                SELECT user_id FROM user_api_userretirementstatus
            )
            UNION SELECT
                original_username AS username,
                user_id
            FROM user_api_userretirementstatus
        ) u

    Import data into ecommerce using:

    CREATE TABLE temp_username_userid
    (
    username VARCHAR(150),
    lms_user_id INT(11),
    PRIMARY KEY(lms_user_id)
    )
    ENGINE = InnoDB;

    LOAD DATA FROM S3 FILE 's3-BUCKET_ID/username_userid'
    INTO TABLE temp_username_userid
    FIELDS TERMINATED BY ','
    OPTIONALLY ENCLOSED BY '"'
    LINES TERMINATED BY '\n'
        (username, lms_user_id)

    CREATE INDEX username_index ON temp_username_userid (username);
    """

    def add_arguments(self, parser):
        parser.add_argument(
            '--max-user-id',
            type=int,
            default=None,
            help="Maximum user id to update"
        )
        parser.add_argument(
{'fraction_non_alphanumeric': 0.06399340840428454, 'fraction_numerical': 0.0038450975006866246, 'mean_word_length': 2.19193689745837, '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': '2364026', 'n_tokens_mistral': 1102, 'n_tokens_neox': 1029, 'n_words': 312}