# Generated by Django 3.0.5 on 2023-06-02 15:30
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('sample', '0001_initial'),
]
operations = [
migrations.RunSQL(
"""
-- Create temporary table for auth_group
CREATE TEMPORARY TABLE temp_auth_group (
id INT PRIMARY KEY,
name VARCHAR(255)
);
-- Insert data into temporary table for auth_group
INSERT INTO temp_auth_group (id, name)
VALUES
(1, 'group1'),
(2, 'group2'),
(3, 'group3');
-- Update existing records in auth_group using temporary table data
UPDATE auth_group
INNER JOIN temp_auth_group ON auth_group.id = temp_auth_group.id
SET auth_group.name = temp_auth_group.name;
-- Insert new records into auth_group from temporary table
INSERT INTO auth_group (id, name)
SELECT id, name FROM temp_auth_group
WHERE id NOT IN (SELECT id FROM auth_group);
-- Drop temporary table for auth_group
DROP TEMPORARY TABLE IF EXISTS temp_auth_group;
"""
),
migrations.RunSQL(
"""
-- Create temporary table for path
CREATE TEMPORARY TABLE temp_path (
path_id INT PRIMARY KEY,
path VARCHAR(255)
);
-- Insert data into temporary table for path
INSERT INTO temp_path (path_id, path)
VALUES
(1, '/sample1/'),
(2, '/sample2/'),
(3, '/sample3/');
-- Update existing records in path using temporary table data
UPDATE path
INNER JOIN temp_path ON path.path_id = temp_path.path_id
SET path.path = temp_path.path;
-- Insert new records into path from temporary table
INSERT INTO path (path_id, path)
SELECT path_id, path FROM temp_path
WHERE path_id NOT IN (SELECT path_id FROM path);
-- Drop temporary table for path
DROP TEMPORARY TABLE IF EXISTS temp_path;
"""
),
migrations.RunSQL(
"""
-- Create temporary table for path_x_group
CREATE TEMPORARY TABLE temp_path_x_group (
path_x_group_id INT PRIMARY KEY,
group_id INT,
path_id INT
);
-- Insert data into temporary table for path_x_group
INSERT INTO temp_path_x_group (path_x_group_id, group_id, path_id)
VALUES
(1, 1, 1),
(2, 1, 2),
(3, 2, 1),
(4, 2, 2),
(5, 2, 3),
(6, 3, 2),
(7, 3, 3);
-- Update existing records in path_x_group using temporary table data
UPDATE path_x_group
INNER JOIN temp_path_x_group ON path_x_group.path_x_group_id = temp_path_x_group.path_x_group_id
SET path_x_group.group_id = temp_path_x_group.group_id, path_x_group.path_id = temp_path_x_group.path_id;
-- Insert new records into path_x_group from temporary table
INSERT INTO path_x_group (path_x_group_id, group_id, path_id)
SELECT path_x_group_id, group_id, path_id FROM temp_path_x_group
WHERE path_x_group_id NOT IN (SELECT path_x_group_id FROM path_x_group);
-- Drop temporary table for path_x_group
DROP TEMPORARY TABLE IF EXISTS temp_path_x_group;
"""
),
]