creeV3Publisher+Version+Action.sql
2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
tee creeV3Publisher+Version+Action.log
SET foreign_key_checks = 0;
create table Publisher (
publisherId int(11) NOT NULL AUTO_INCREMENT,
validatedVersion_publisherVersionId int(11),
PRIMARY KEY ('publisherId')
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
insert into Publisher (publisherId, validatedVersion_publisherVersionId)
select ID_EDITEUR, ID_EDITEUR from editeur;
create table PublisherVersion (
publisherVersionId int(11) NOT NULL AUTO_INCREMENT,
publisher_publisherId int(11) NOT NULL,
publisherName varchar(50) NOT NULL,
publisherStreetAddress varchar(300),
publisherPostalCode varchar(15),
publisherPostOfficeBoxNumber varchar(50),
publisherAddressRegion varchar(50),
publisherAddressLocality varchar(50),
publisherAddressCountry_countryId int(11),
publisherTelephone varchar(25),
publisherEmail varchar(50),
publisherURL varchar(100),
publisherHistory longtext,
publisherVersionAuthor_userId int(11),
publisherVersionDatetime DATETIME,
PRIMARY KEY ('publisherVersionId')
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
insert into PublisherVersion (publisherVersionId, publisher_publisherId,
publisherName, publisherStreetAddress, publisherPostalCode,
publisherPostOfficeBoxNumber, publisherAddressRegion,
publisherAddressLocality, publisherAddressCountry_countryId,
publisherTelephone, publisherEmail, publisherURL,
publisherHistory, publisherVersionAuthor_userId, publisherVersionDatetime)
select ID_EDITEUR, ID_EDITEUR, NOM_EDITEUR, ADR_EDITEUR, CP_EDITEUR, NULL,
NULL, VILLE, countryId, TEL_EDITEUR, EMAIL_EDITEUR, URL_EDITEUR,
HISTORIQUE, ID_UTILISATEUR, DATE_ACTION
from editeur e
left join Country on countryName = e.PAYS
join journal j on j.ID_JOURNALISABLE = e.ID_EDITEUR
where j.DATE_ACTION = (select max(DATE_ACTION) from journal j2
where j2.ID_JOURNALISABLE = e.ID_EDITEUR)
union
select ID_EDITEUR, ID_EDITEUR, NOM_EDITEUR, ADR_EDITEUR, CP_EDITEUR, NULL,
NULL, VILLE, countryId, TEL_EDITEUR, EMAIL_EDITEUR, URL_EDITEUR,
HISTORIQUE, null, null
from editeur e
left join Country on countryName = e.PAYS
where ID_EDITEUR not in (select distinct ID_JOURNALISABLE from journal)
;
create table PublisherAction (
publisherActionId int(11) NOT NULL AUTO_INCREMENT,
ActionType TINYINT UNSIGNED NOT NULL,
publisherActionAuthor_userId int(11) NOT NULL,
publisherVersion_publisherVersionId int(11) NOT NULL,
publisherActionDatetime DATETIME,
publisher_publisherId int(11) NOT NULL,
PRIMARY KEY ('publisherActionId')
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
insert into PublisherAction (ActionType, publisherActionAuthor_userId,
publisherVersion_publisherVersionId, publisherActionDatetime,
publisher_publisherId)
select 0, ID_UTILISATEUR, ID_EDITEUR, DATE_ACTION, ID_EDITEUR
from editeur e
join journal j on j.ID_JOURNALISABLE = e.ID_EDITEUR
where j.DATE_ACTION = (select max(DATE_ACTION) from journal j2
where j2.ID_JOURNALISABLE = e.ID_EDITEUR)
;
SET foreign_key_checks = 1;
show create table Publisher;
show create table PublisherVersion;
show create table PublisherAction;