2023-01-03 22:16:29 +01:00
|
|
|
-- account
|
|
|
|
DELETE FROM "user"
|
|
|
|
WHERE username = 'admin';
|
|
|
|
|
|
|
|
INSERT INTO "user"
|
|
|
|
(user_id, username, password, role, created_at, updated_at, deleted_at)
|
|
|
|
SELECT account_uuid,
|
|
|
|
username,
|
|
|
|
password,
|
|
|
|
CASE WHEN is_admin = true THEN 'admin' ELSE 'user' END,
|
|
|
|
created_at,
|
|
|
|
updated_at,
|
|
|
|
NULL
|
2023-01-11 00:01:41 +01:00
|
|
|
FROM v1_account
|
|
|
|
WHERE NOT EXISTS (SELECT 1 FROM "user");
|
2023-01-03 22:16:29 +01:00
|
|
|
|
|
|
|
-- website
|
|
|
|
INSERT INTO website
|
|
|
|
(website_id, name, domain, share_id, rev_id, user_id, team_id, created_at)
|
|
|
|
SELECT website_uuid,
|
|
|
|
name,
|
|
|
|
domain,
|
|
|
|
share_id,
|
|
|
|
0 rev_id,
|
|
|
|
a.account_uuid,
|
|
|
|
NULL team_id,
|
|
|
|
a.created_at
|
|
|
|
FROM v1_website w
|
|
|
|
JOIN v1_account a
|
2023-01-11 00:01:41 +01:00
|
|
|
ON a.user_id = w.user_id
|
|
|
|
WHERE NOT EXISTS (SELECT 1 FROM website);
|
2023-01-03 22:16:29 +01:00
|
|
|
|
|
|
|
-- session
|
|
|
|
INSERT INTO session
|
|
|
|
(session_id, website_id, hostname, browser, os, device, screen, language, country)
|
|
|
|
SELECT session_uuid,
|
|
|
|
w.website_uuid,
|
|
|
|
hostname,
|
|
|
|
browser,
|
|
|
|
os,
|
|
|
|
device,
|
|
|
|
screen,
|
|
|
|
language,
|
|
|
|
country
|
|
|
|
FROM v1_session s
|
|
|
|
JOIN v1_website w
|
2023-01-11 00:01:41 +01:00
|
|
|
ON w.website_id = s.website_id
|
|
|
|
WHERE NOT EXISTS (SELECT 1 FROM session);
|
2023-01-03 22:16:29 +01:00
|
|
|
|
|
|
|
-- pageview
|
|
|
|
INSERT INTO website_event
|
|
|
|
(event_id, website_id, session_id, created_at, url, referrer, event_type)
|
|
|
|
SELECT gen_random_uuid() event_id,
|
|
|
|
w.website_uuid,
|
|
|
|
s.session_uuid,
|
|
|
|
p.created_at,
|
|
|
|
p.url,
|
|
|
|
p.referrer,
|
|
|
|
1 event_type
|
|
|
|
FROM v1_pageview p
|
|
|
|
JOIN v1_session s
|
2023-01-04 09:26:31 +01:00
|
|
|
ON s.session_id = p.session_id
|
2023-01-03 22:16:29 +01:00
|
|
|
JOIN v1_website w
|
2023-01-11 00:01:41 +01:00
|
|
|
ON w.website_id = s.website_id
|
|
|
|
WHERE NOT EXISTS (SELECT 1 FROM website_event WHERE event_type = 1);
|
2023-01-03 22:16:29 +01:00
|
|
|
|
|
|
|
-- event / event_data
|
|
|
|
INSERT INTO website_event
|
|
|
|
(event_id, website_id, session_id, created_at, url, event_type, event_name, event_data)
|
|
|
|
SELECT e.event_uuid,
|
|
|
|
w.website_uuid,
|
|
|
|
s.session_uuid,
|
|
|
|
e.created_at,
|
|
|
|
e.url,
|
2023-01-04 09:26:31 +01:00
|
|
|
2 event_type,
|
2023-01-03 22:16:29 +01:00
|
|
|
e.event_name,
|
|
|
|
ed.event_data
|
|
|
|
FROM v1_event e
|
|
|
|
JOIN v1_session s
|
2023-01-04 09:26:31 +01:00
|
|
|
ON s.session_id = e.session_id
|
2023-01-03 22:16:29 +01:00
|
|
|
JOIN v1_website w
|
|
|
|
ON w.website_id = s.website_id
|
|
|
|
LEFT JOIN v1_event_data ed
|
2023-01-11 00:01:41 +01:00
|
|
|
ON ed.event_id = e.event_id
|
|
|
|
WHERE NOT EXISTS (SELECT 1 FROM website_event WHERE event_type = 2);
|