Jean-Francois Leveque

Migration éditeur et adaptation import.sql

1 +create table Country (
2 + countryId int(11) NOT NULL AUTO_INCREMENT,
3 + countryName varchar(100) DEFAULT NULL,
4 + PRIMARY KEY ('countryId')
5 +) ENGINE=InnoDB DEFAULT CHARSET=utf8;
6 +
7 +insert into Country (countryId, countryName)
8 + select ID_PAYS, LIB_PAYS from pays;
9 +
10 +show create table Country;
...\ No newline at end of file ...\ No newline at end of file
1 +create table Publisher (
2 + publisherId int(11) NOT NULL AUTO_INCREMENT,
3 + validatedVersion int(11),
4 + PRIMARY KEY ('publisherId')
5 +) ENGINE=InnoDB DEFAULT CHARSET=utf8;
6 +
7 +insert into Publisher (publisherId, validatedVersion)
8 + select ID_EDITEUR, ID_EDITEUR from editeur;
9 +
10 +create table PublisherVersion (
11 + publisherVersionId int(11) NOT NULL AUTO_INCREMENT,
12 + publisher_publisherId int(11) NOT NULL,
13 + publisherName varchar(50) NOT NULL,
14 + publisherStreetAddress varchar(300),
15 + publisherPostalCode varchar(15),
16 + publisherPostOfficeBoxNumber varchar(50),
17 + publisherAddressRegion varchar(50),
18 + publisherAddressLocality varchar(50),
19 + publisherAddressCountry_countryId int(11),
20 + publisherTelephone varchar(25),
21 + publisherEmail varchar(50),
22 + publisherURL varchar(100),
23 + publisherActive TINYINT(1),
24 + publisherHistory longtext,
25 + publisherVersionAuthor_userId int(11),
26 + publisherVersionDatetime DATETIME,
27 + PRIMARY KEY ('publisherVersionId')
28 +) ENGINE=InnoDB DEFAULT CHARSET=utf8;
29 +
30 +insert into PublisherVersion (publisherVersionId, publisher_publisherId,
31 + publisherName, publisherStreetAddress, publisherPostalCode,
32 + publisherPostOfficeBoxNumber, publisherAddressRegion,
33 + publisherAddressLocality, publisherAddressCountry_countryId,
34 + publisherTelephone, publisherEmail, publisherURL, publisherActive,
35 + publisherHistory, publisherVersionAuthor_userId, publisherVersionDatetime)
36 +select ID_EDITEUR, ID_EDITEUR, NOM_EDITEUR, ADR_EDITEUR, CP_EDITEUR, NULL,
37 + NULL, VILLE, countryId, TEL_EDITEUR, EMAIL_EDITEUR, URL_EDITEUR, NULL,
38 + HISTORIQUE, ID_UTILISATEUR, DATE_ACTION
39 +from editeur e
40 +left join Country on countryName = e.PAYS
41 +join journal j on j.ID_JOURNALISABLE = e.ID_EDITEUR
42 +where j.DATE_ACTION = (select max(DATE_ACTION) from journal j2
43 + where j2.ID_JOURNALISABLE = e.ID_EDITEUR)
44 +union
45 +select ID_EDITEUR, ID_EDITEUR, NOM_EDITEUR, ADR_EDITEUR, CP_EDITEUR, NULL,
46 + NULL, VILLE, countryId, TEL_EDITEUR, EMAIL_EDITEUR, URL_EDITEUR, NULL,
47 + HISTORIQUE, null, null
48 +from editeur e
49 +left join Country on countryName = e.PAYS
50 +where ID_EDITEUR not in (select distinct ID_JOURNALISABLE from journal)
51 +;
52 +
53 +create table PublisherAction (
54 + publisherActionId int(11) NOT NULL AUTO_INCREMENT,
55 + ActionType TINYINT UNSIGNED NOT NULL,
56 + publisherActionAuthor_userId int(11) NOT NULL,
57 + publisherVersion_publisherVersionId int(11) NOT NULL,
58 + publisherActionDatetime DATETIME,
59 + publisher_publisherId int(11) NOT NULL,
60 + PRIMARY KEY ('publisherActionId')
61 +) ENGINE=InnoDB DEFAULT CHARSET=utf8;
62 +
63 +insert into PublisherAction (ActionType, publisherActionAuthor_userId,
64 + publisherVersion_publisherVersionId, publisherActionDatetime,
65 + publisher_publisherId)
66 +select 0, ID_UTILISATEUR, ID_EDITEUR, DATE_ACTION, ID_EDITEUR
67 +from editeur e
68 +join journal j on j.ID_JOURNALISABLE = e.ID_EDITEUR
69 +where j.DATE_ACTION = (select max(DATE_ACTION) from journal j2
70 + where j2.ID_JOURNALISABLE = e.ID_EDITEUR)
71 +;
72 +
73 +show create table Publisher;
74 +
75 +show create table PublisherVersion;
76 +
77 +show create table PublisherAction;
...\ No newline at end of file ...\ No newline at end of file
1 +source normalisePays.sql
2 +source creeV3Country.sql
3 +source creeV3Publisher+Version+Action.sql
...\ No newline at end of file ...\ No newline at end of file
1 +-- PREPARATION TABLE editeur
2 +-- Standardisation des valeurs de PAYS dans editeur
3 +update editeur set PAYS='Allemagne' where PAYS in ('Deutschland');
4 +update editeur set PAYS='Australie' where PAYS in ('Australia');
5 +update editeur set PAYS='Espagne' where PAYS in ('España');
6 +update editeur set PAYS='Pologne' where PAYS in ('Polska');
7 +update editeur set PAYS='Royaume-Uni' where PAYS in ('United Kingdom', 'Royaume Uni', 'Grande-Bretagne', 'United Kingdoms', 'Royaumes Unis', 'Angleterre', 'UK');
8 +update editeur set PAYS='États-Unis' where PAYS in ('USA', 'Etats Unis', 'Etats-Unis d\'Amérique', 'Etats Unis d\'Amérique', 'Caroline du Sud');
9 +update editeur set PAYS='République thèque' where PAYS in ('Ceska Republika');
10 +update editeur set PAYS='Finlande' where PAYS in ('Suomi / Finlande');
11 +update editeur set PAYS='Suède' where PAYS in ('Sverige / Suède');
12 +update editeur set PAYS='Italie' where PAYS in ('Italia');
13 +update editeur set PAYS='Grèce' where PAYS in ('Ellada / Grèce', 'Ellada / Grèce');
14 +update editeur set PAYS='Brésil' where PAYS in ('Brasil/Brésil', 'Brasil', 'Brasilia');
15 +update editeur set PAYS='Nouvelle-Zélande' where PAYS in ('New Zealand', 'New-Zeland');
16 +-- Suppression d'un pays imaginaire
17 +-- http://www.legrog.org/editeurs/hugin-munin
18 +update editeur set PAYS=NULL where PAYS='France / Canada';
19 +
20 +-- PREPARATION TABLE pays
21 +-- Ajouts dans la table pays pour intégration
22 +insert into pays (LIB_PAYS) values ('République thèque');
23 +insert into pays (LIB_PAYS) values ('Finlande');
24 +insert into pays (LIB_PAYS) values ('Suède');
25 +insert into pays (LIB_PAYS) values ('Italie');
26 +insert into pays (LIB_PAYS) values ('Grèce');
27 +insert into pays (LIB_PAYS) values ('Brésil');
28 +insert into pays (LIB_PAYS) values ('Nouvelle-Zélande');
29 +insert into pays (LIB_PAYS) values ('Japon');
30 +insert into pays (LIB_PAYS) values ('Corée du Sud');
31 +insert into pays (LIB_PAYS) values ('Pays-Bas');
32 +insert into pays (LIB_PAYS) values ('Hongrie');
33 +update pays set LIB_PAYS='États-Unis' where LIB_PAYS='USA';
34 +
35 +-- CONTROLE MATCHING
36 +select ID_EDITEUR from editeur
37 +where PAYS is not null
38 +and PAYS not in (select LIB_PAYS from pays);
...\ No newline at end of file ...\ No newline at end of file
1 -- INSERT avec identifiants car GenerationType.AUTO a du être changé en GenerationType.IDENTITY (2016-11-21) 1 -- INSERT avec identifiants car GenerationType.AUTO a du être changé en GenerationType.IDENTITY (2016-11-21)
2 //INSERT INTO ActionType (actionTypeId, actionTypeName) VALUES (1, 'Validate'); 2 //INSERT INTO ActionType (actionTypeId, actionTypeName) VALUES (1, 'Validate');
3 -INSERT INTO Country (countryId, countryName) VALUES 3 +-- INSERT INTO Country (countryId, countryName) VALUES
4 - (1, 'France'), 4 +-- (1, 'France'),
5 - (2, 'Suisse'), 5 +-- (2, 'Suisse'),
6 - (3, 'Belgique'), 6 +-- (3, 'Belgique'),
7 - (4, 'Canada'), 7 +-- (4, 'Canada'),
8 - (5, 'États-Unis d''Amérique'), 8 +-- (5, 'États-Unis d''Amérique'),
9 - (6, 'Australie'), 9 +-- (6, 'Australie'),
10 - (7, 'Espagne'), 10 +-- (7, 'Espagne'),
11 - (8, 'Portugal'), 11 +-- (8, 'Portugal'),
12 - (9, 'Royaume-Uni'), 12 +-- (9, 'Royaume-Uni'),
13 - (10, 'Allemagne'), 13 +-- (10, 'Allemagne'),
14 - (11, 'Pologne'), 14 +-- (11, 'Pologne'),
15 - (12, 'Italie'); 15 +-- (12, 'Italie');
16 INSERT INTO Person (userId, username, password, firstName, lastName, nickname, email, activated, anonymous, visible, 16 INSERT INTO Person (userId, username, password, firstName, lastName, nickname, email, activated, anonymous, visible,
17 criticProvider) VALUES 17 criticProvider) VALUES
18 - (1, 'one', 'one', 'Derrick', 'Moss', 'one', 'one@raza.org', TRUE, FALSE, TRUE, TRUE), 18 + (1, '1', null, '1f', '1l', '1n', '1@raza.org', TRUE, TRUE, TRUE, TRUE),
19 - (2, 'two', 'two', 'Portia', 'Lin', 'two', 'two@raza.org', TRUE, FALSE, TRUE, TRUE), 19 + (2, '2', null, '2f', '2l', '2n', '2@raza.org', TRUE, FALSE, TRUE, TRUE),
20 - (3, 'three', 'three', 'Marcus', 'Boone', 'three', 'three@raza.org', TRUE, FALSE, TRUE, TRUE), 20 + (3, '3', null, '3f', '3l', '3n', '3@raza.org', TRUE, FALSE, TRUE, TRUE),
21 - (4, 'four', 'four', 'Ryo', 'Tetsuda', 'four', 'four@raza.org', TRUE, FALSE, TRUE, TRUE), 21 + (4, '4', null, '4f', '4l', '4n', '4@raza.org', TRUE, FALSE, TRUE, TRUE),
22 - (5, 'five', 'five', 'Emily', 'Kolburn', 'five', 'five@raza.org', TRUE, FALSE, TRUE, TRUE), 22 + (5, '5', null, '5f', '5l', '5n', '5@raza.org', TRUE, FALSE, TRUE, TRUE),
23 + (8, '8', null, '8f', '8l', '8n', '8@raza.org', TRUE, FALSE, TRUE, TRUE),
24 + (9, '9', null, '9f', '9l', '9n', '9@raza.org', TRUE, FALSE, TRUE, TRUE),
25 + (10, '10', null, '10f', '10l', '10n', '10@raza.org', TRUE, FALSE, TRUE, TRUE),
26 + (11, '11', null, '11f', '11l', '11n', '11@raza.org', TRUE, FALSE, TRUE, TRUE),
27 + (12, '12', null, '12f', '12l', '12n', '12@raza.org', TRUE, TRUE, TRUE, TRUE),
28 + (13, '13', null, '13f', '13l', '13n', '13@raza.org', TRUE, FALSE, TRUE, TRUE),
29 + (17, '17', null, '17f', '17l', '17n', '17@raza.org', TRUE, FALSE, TRUE, TRUE),
30 + (21, '21', null, '21f', '21l', '21n', '21@raza.org', TRUE, FALSE, TRUE, TRUE),
31 + (22, '22', null, '22f', '22l', '22n', '22@raza.org', TRUE, TRUE, TRUE, TRUE),
32 + (43, '43', null, '43f', '43l', '43n', '43@raza.org', TRUE, TRUE, TRUE, TRUE),
33 + (48, '48', null, '48f', '48l', '48n', '48@raza.org', TRUE, FALSE, TRUE, TRUE),
34 + (57, '57', null, '57f', '57l', '57n', '57@raza.org', TRUE, TRUE, TRUE, TRUE),
35 + (109, '109', null, '109f', '109l', '109n', '109@raza.org', TRUE, FALSE, TRUE, TRUE),
36 + (111, '111', null, '111f', '111l', '111n', '111@raza.org', TRUE, TRUE, TRUE, TRUE),
37 + (127, '127', null, '127f', '127l', '127n', '127@raza.org', TRUE, TRUE, TRUE, TRUE),
38 + (170, '170', null, '170f', '170l', '170n', '170@raza.org', TRUE, FALSE, TRUE, TRUE),
39 + (185, '185', null, '185f', '185l', '185n', '185@raza.org', TRUE, FALSE, TRUE, TRUE),
40 + (254, '254', null, '254f', '254l', '254n', '254@raza.org', TRUE, FALSE, TRUE, TRUE),
41 + (311, '311', null, '311f', '311l', '311n', '311@raza.org', TRUE, FALSE, TRUE, TRUE),
42 + (509, '509', null, '509f', '509l', '509n', '509@raza.org', TRUE, FALSE, TRUE, TRUE),
43 + (1017, '1017', null, '1017f', '1017l', '1017n', '1017@raza.org', TRUE, TRUE, TRUE, TRUE),
44 + (1028, '1028', null, '1028f', '1028l', '1028n', '1028@raza.org', TRUE, FALSE, TRUE, TRUE),
45 + (1152, '1152', null, '1152f', '1152l', '1152n', '1152@raza.org', TRUE, FALSE, TRUE, TRUE),
46 + (2316, '2316', null, '2316f', '2316l', '2316n', '2316@raza.org', TRUE, FALSE, TRUE, TRUE),
47 + (2374, '2374', null, '2374f', '2374l', '2374n', '2374@raza.org', TRUE, FALSE, TRUE, TRUE),
48 + (3362, '3362', null, '3362f', '3362l', '3362n', '3362@raza.org', TRUE, TRUE, TRUE, TRUE),
49 + (3431, '3431', null, '3431f', '3431l', '3431n', '3431@raza.org', TRUE, FALSE, TRUE, TRUE),
23 (6, 'six', 'six', 'Kal', 'Varrik', 'six', 'six@raza.org', TRUE, FALSE, TRUE, TRUE); 50 (6, 'six', 'six', 'Kal', 'Varrik', 'six', 'six@raza.org', TRUE, FALSE, TRUE, TRUE);
24 51
25 -INSERT INTO Publisher (publisherId) VALUES (1), (2), (3), (4); 52 +-- INSERT INTO Publisher (publisherId) VALUES (1), (2), (3), (4);
26 53
27 -INSERT INTO PublisherVersion (publisherVersionId, publisher_publisherId, publisherName, publisherStreetAddress, 54 +-- INSERT INTO PublisherVersion (publisherVersionId, publisher_publisherId, publisherName, publisherStreetAddress,
28 - publisherPostalCode, publisherPostOfficeBoxNumber, publisherAddressRegion, 55 +-- publisherPostalCode, publisherPostOfficeBoxNumber, publisherAddressRegion,
29 - publisherAddressLocality, publisherAddressCountry_countryId, publisherTelephone, 56 +-- publisherAddressLocality, publisherAddressCountry_countryId, publisherTelephone,
30 - publisherEmail, publisherURL, publisherActive, publisherHistory, 57 +-- publisherEmail, publisherURL, publisherActive, publisherHistory,
31 - publisherVersionAuthor_userId, publisherVersionDatetime) VALUES 58 +-- publisherVersionAuthor_userId, publisherVersionDatetime) VALUES
32 - (1, 1, 'GRôG', '', '', '', '', '', 1, '', 'passerelle@legrog.org', 'www.legrog.org', TRUE, 'Ouvert…', 1, {ts '2000-05-08 00:00:47'}), 59 +-- (1, 1, 'GRôG', '', '', '', '', '', 1, '', 'passerelle@legrog.org', 'www.legrog.org', TRUE, 'Ouvert…', 1, {ts '2000-05-08 00:00:47'}),
33 - (2, 2, 'Rôliste TV', NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, 'www.rolistetv.com', TRUE, 'Ouvert…', 3, {ts '2010-05-20 08:43:16'}), 60 +-- (2, 2, 'Rôliste TV', NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, 'www.rolistetv.com', TRUE, 'Ouvert…', 3, {ts '2010-05-20 08:43:16'}),
34 - (3, 3, 'La Vouivre', NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, 'la-vouivre.com', TRUE, 'Ouvert…', 1, {ts '2000-01-01 00:02:33'}), 61 +-- (3, 3, 'La Vouivre', NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, 'la-vouivre.com', TRUE, 'Ouvert…', 1, {ts '2000-01-01 00:02:33'}),
35 - (4, 3, 'La Vouivre', NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, 'la-vouivre.com', FALSE, '… en 2015', 2, {ts '2015-01-01 00:05:22'}), 62 +-- (4, 3, 'La Vouivre', NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, 'la-vouivre.com', FALSE, '… en 2015', 2, {ts '2015-01-01 00:05:22'}),
36 - (5, 4, 'Archmagus', NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, 'archimage.net', TRUE, 'Ouvert…', 4, {ts '2016-10-14 10:56:03'}); 63 +-- (5, 4, 'Archmagus', NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, 'archimage.net', TRUE, 'Ouvert…', 4, {ts '2016-10-14 10:56:03'});
37 -UPDATE Publisher SET validatedVersion_publisherVersionId = 1 WHERE publisherId = 1; 64 +-- UPDATE Publisher SET validatedVersion_publisherVersionId = 1 WHERE publisherId = 1;
38 -UPDATE Publisher SET validatedVersion_publisherVersionId = 2 WHERE publisherId = 2; 65 +-- UPDATE Publisher SET validatedVersion_publisherVersionId = 2 WHERE publisherId = 2;
39 -UPDATE Publisher SET validatedVersion_publisherVersionId = 4 WHERE publisherId = 3; 66 +-- UPDATE Publisher SET validatedVersion_publisherVersionId = 4 WHERE publisherId = 3;
40 67
41 -INSERT INTO PublisherAction (publisherActionId, actionType, publisherActionAuthor_userId, 68 +-- INSERT INTO PublisherAction (publisherActionId, actionType, publisherActionAuthor_userId,
42 - publisherVersion_publisherVersionId, publisherActionDatetime, publisher_publisherId) VALUES 69 +-- publisherVersion_publisherVersionId, publisherActionDatetime, publisher_publisherId) VALUES
43 - (1, 0, 2, 1, {ts '2000-05-08 12:00:28'}, 1), 70 +-- (1, 0, 2, 1, {ts '2000-05-08 12:00:28'}, 1),
44 - (2, 0, 1, 2, {ts '2010-06-20 14:27:35'}, 2), 71 +-- (2, 0, 1, 2, {ts '2010-06-20 14:27:35'}, 2),
45 - (3, 0, 1, 4, {ts '2015-01-01 16:18:17'}, 3); 72 +-- (3, 0, 1, 4, {ts '2015-01-01 16:18:17'}, 3);
46 73
47 INSERT INTO UserRole (userRoleId, rolename, visible) VALUES 74 INSERT INTO UserRole (userRoleId, rolename, visible) VALUES
48 (1, 'VISITEUR', TRUE), 75 (1, 'VISITEUR', TRUE),
......