Skip to content

Commit 97d02ee

Browse files
committed
Adjust SQL scripts for hibernate-mapping module
1 parent f477866 commit 97d02ee

5 files changed

+74
-66
lines changed
Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,33 @@
11

2-
create table AUTHOR
3-
(
4-
id int not null auto_increment,
5-
name varchar(100) not null,
6-
primary key (id)
2+
create table AUTHOR (
3+
ID int primary key autoincrement,
4+
NAME varchar(100) not null
75
);
86

9-
create table ADDRESS
10-
(
11-
id int not null auto_increment,
12-
country varchar(50) not null,
13-
town varchar(50) not null,
14-
street_and_building varchar(100) not null,
15-
primary key (id)
7+
create table ADDRESS (
8+
ID int primary key autoincrement,
9+
COUNTRY varchar(50) not null,
10+
TOWN varchar(50) not null,
11+
STREET_AND_BUILDING varchar(100) not null
1612
);
1713

18-
create table PUBLISHER
19-
(
20-
id int not null auto_increment,
21-
name varchar(100) not null,
22-
address_id int not null,
23-
primary key (id),
24-
foreign key (address_id) references ADDRESS(id)
14+
create table PUBLISHER (
15+
ID int primary key autoincrement,
16+
NAME varchar(100) not null,
17+
ADDRESS_ID int not null,
18+
foreign key (ADDRESS_ID) references ADDRESS(ID)
2519
);
2620

27-
create table BOOK
28-
(
29-
id int not null auto_increment,
30-
title varchar(100) not null,
31-
publisher_id int not null,
32-
primary key (id),
33-
foreign key (publisher_id) references PUBLISHER(id)
21+
create table BOOK (
22+
ID int not null primary key autoincrement,
23+
TITLE varchar(100) not null,
24+
PUBLISHER_ID int not null,
25+
foreign key (PUBLISHER_ID) references PUBLISHER(ID)
3426
);
3527

36-
create table BOOK_AUTHOR
37-
(
38-
book_id INT NOT NULL,
39-
author_id INT NOT NULL,
40-
FOREIGN KEY (book_id) REFERENCES BOOK(id),
41-
FOREIGN KEY (author_id) REFERENCES AUTHOR(id)
28+
create table BOOK_AUTHOR (
29+
BOOK_ID int not null,
30+
AUTHOR_ID int not null,
31+
foreign key (BOOK_ID) references BOOK(ID),
32+
foreign key (AUTHOR_ID) references AUTHOR(ID)
4233
);
Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11

2-
insert into AUTHOR (name) values ('Daniel Defo');
3-
insert into AUTHOR (name) values ('Samuil Marshak');
4-
insert into AUTHOR (name) values ('Kent Bek');
2+
insert into AUTHOR(NAME) values
3+
('Daniel Defo'),
4+
('Samuil Marshak'),
5+
('Kent Bek');
56

6-
insert into ADDRESS (country, town, street_and_building) values ('Russia', 'Moscow', 'Esenina st., 13-234');
7-
insert into ADDRESS (country, town, street_and_building) values ('United States', 'Dallas', 'Independence ave., 56-12');
7+
insert into ADDRESS(COUNTRY, TOWN, STREET_AND_BUILDING) values
8+
('Russia', 'Moscow', 'Esenina st., 13-234'),
9+
('United States', 'Dallas', 'Independence ave., 56-12');
810

9-
insert into PUBLISHER (name, address_id) values ('Blagovest', 2);
10-
insert into PUBLISHER (name, address_id) values ('Piter', 1);
11+
insert into PUBLISHER(NAME, ADDRESS_ID) values
12+
('Blagovest', 2),
13+
('Piter', 1);
1114

12-
insert into BOOK (title, publisher_id) values ('Kolobok', 1);
13-
insert into BOOK (title, publisher_id) values ('Repka', 2);
14-
insert into BOOK (title, publisher_id) values ('Tri porosenka', 2);
15-
insert into BOOK (title, publisher_id) values ('Buratino', 1);
15+
insert into BOOK(TITLE, PUBLISHER_ID) values
16+
('Kolobok', 1),
17+
('Repka', 2),
18+
('Tri porosenka', 2),
19+
('Buratino', 1);
1620

17-
insert into BOOK_AUTHOR (book_id, author_id) values (1, 1);
18-
insert into BOOK_AUTHOR (book_id, author_id) values (2, 1);
19-
insert into BOOK_AUTHOR (book_id, author_id) values (2, 3);
20-
insert into BOOK_AUTHOR (book_id, author_id) values (3, 2);
21-
insert into BOOK_AUTHOR (book_id, author_id) values (4, 1);
21+
insert into BOOK_AUTHOR(BOOK_ID, AUTHOR_ID) values
22+
(1, 1),
23+
(2, 1),
24+
(2, 3),
25+
(3, 2),
26+
(4, 1);
27+
28+
select count(*) from AUTHOR union select count(*) from ADDRESS union select count(*) from PUBLISHER union
29+
select count(*) from BOOK union select count(*) from BOOK_AUTHOR;

hibernate-mappings/src/main/resources/db_migration/V3__Create_and_populate_tables_with_inheritance.sql

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
create table ITEMS (
3+
ID int not null primary key autoincrement,
4+
NAME varchar(100) not null,
5+
PRICE decimal(5, 2) not null,
6+
WEIGHT decimal(5, 2) not null,
7+
LENGTH decimal(5, 2),
8+
WIDTH decimal(5, 2),
9+
HEIGHT decimal(5, 2),
10+
DESCRIPTION varchar(250),
11+
ITEM_TYPE varchar(10) not null
12+
);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
insert into ITEMS (ITEM_TYPE, NAME, PRICE, WEIGHT, LENGTH, WIDTH, HEIGHT) values
3+
('3-size', 'Milk packet', 1.5, 1, 15, 5, 10);
4+
insert into ITEMS (ITEM_TYPE, NAME, PRICE, WEIGHT, LENGTH, WIDTH) values
5+
('2-size', 'Picture', 29.9, 100, 600, 15),
6+
('2-size', 'Copper tube', 19.5, 140, 200, 12);
7+
insert into ITEMS (ITEM_TYPE, NAME, PRICE, WEIGHT, LENGTH) values
8+
('1-size', 'Copper cable', 20.5, 10.5, 230);
9+
insert into ITEMS (ITEM_TYPE, NAME, PRICE, WEIGHT) values
10+
('0-size', 'Toy house', 4.9, 0.05);
11+
12+
select count(*) from ITEMS;
13+
14+
-- Show info about tables in DB:
15+
select TABLE_NAME, TABLE_TYPE, ROW_COUNT_ESTIMATE from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='PUBLIC';

0 commit comments

Comments
 (0)