bamoo456
5/29/2018 - 7:52 AM

Mysql JSON, column names, migrate data to trash

-- Check the fields of target table first
select column_name from information_schema.columns where table_schema = DATABASE() AND table_name='TestTable';

-- Migrate the data to the trash
INSERT INTO Trash (model, modelId, eventId, content, createdAt, createdBy, updatedAt, updatedBy)
SELECT 'tablename', id as modelId, eventId, JSON_OBJECT("field1", field1, "field2", field2), CURRENT_TIME, 'test', CURRENT_TIME, 'test' from TestTable 
WHERE id IN (123);

-- Remve the data from original table

-- commit