Skip to content

Commit dbaac15

Browse files
author
kwan
committed
Fix mysql
1 parent 1c800a3 commit dbaac15

File tree

6 files changed

+150
-189
lines changed

6 files changed

+150
-189
lines changed
Lines changed: 22 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
--
2-
-- Turn off autocommit and start a transaction so that we can use the temp tables
3-
--
41

5-
SET AUTOCOMMIT FALSE;
62

7-
START TRANSACTION;
83

9-
--
10-
-- Insert client information into the temporary tables. To add clients to the HSQL database, edit things here.
11-
--
4+
SET AUTOCOMMIT=0;
5+
6+
START TRANSACTION;
127

138
INSERT INTO client_details_TEMP (client_id, client_secret, client_name, dynamically_registered, refresh_token_validity_seconds, access_token_validity_seconds, id_token_validity_seconds, allow_introspection) VALUES
149
('client', 'secret', 'Test Client', false, null, 3600, 600, true);
@@ -18,7 +13,7 @@ INSERT INTO client_scope_TEMP (owner_id, scope) VALUES
1813
('client', 'profile'),
1914
('client', 'email'),
2015
('client', 'address'),
21-
('client', 'phone'),
16+
('client', 'phone2'),
2217
('client', 'offline_access');
2318

2419
INSERT INTO client_redirect_uri_TEMP (owner_id, redirect_uri) VALUES
@@ -30,40 +25,24 @@ INSERT INTO client_grant_type_TEMP (owner_id, grant_type) VALUES
3025
('client', 'urn:ietf:params:oauth:grant_type:redelegate'),
3126
('client', 'implicit'),
3227
('client', 'refresh_token');
33-
34-
--
35-
-- Merge the temporary clients safely into the database. This is a two-step process to keep clients from being created on every startup with a persistent store.
36-
--
37-
38-
MERGE INTO client_details
39-
USING (SELECT client_id, client_secret, client_name, dynamically_registered, refresh_token_validity_seconds, access_token_validity_seconds, id_token_validity_seconds, allow_introspection FROM client_details_TEMP) AS vals(client_id, client_secret, client_name, dynamically_registered, refresh_token_validity_seconds, access_token_validity_seconds, id_token_validity_seconds, allow_introspection)
40-
ON vals.client_id = client_details.client_id
41-
WHEN NOT MATCHED THEN
42-
INSERT (client_id, client_secret, client_name, dynamically_registered, refresh_token_validity_seconds, access_token_validity_seconds, id_token_validity_seconds, allow_introspection) VALUES(client_id, client_secret, client_name, dynamically_registered, refresh_token_validity_seconds, access_token_validity_seconds, id_token_validity_seconds, allow_introspection);
43-
44-
MERGE INTO client_scope
45-
USING (SELECT id, scope FROM client_scope_TEMP, client_details WHERE client_details.client_id = client_scope_TEMP.owner_id) AS vals(id, scope)
46-
ON vals.id = client_scope.owner_id AND vals.scope = client_scope.scope
47-
WHEN NOT MATCHED THEN
48-
INSERT (owner_id, scope) values (vals.id, vals.scope);
49-
50-
MERGE INTO client_redirect_uri
51-
USING (SELECT id, redirect_uri FROM client_redirect_uri_TEMP, client_details WHERE client_details.client_id = client_redirect_uri_TEMP.owner_id) AS vals(id, redirect_uri)
52-
ON vals.id = client_redirect_uri.owner_id AND vals.redirect_uri = client_redirect_uri.redirect_uri
53-
WHEN NOT MATCHED THEN
54-
INSERT (owner_id, redirect_uri) values (vals.id, vals.redirect_uri);
55-
56-
MERGE INTO client_grant_type
57-
USING (SELECT id, grant_type FROM client_grant_type_TEMP, client_details WHERE client_details.client_id = client_grant_type_TEMP.owner_id) AS vals(id, grant_type)
58-
ON vals.id = client_grant_type.owner_id AND vals.grant_type = client_grant_type.grant_type
59-
WHEN NOT MATCHED THEN
60-
INSERT (owner_id, grant_type) values (vals.id, vals.grant_type);
61-
62-
--
63-
-- Close the transaction and turn autocommit back on
64-
--
28+
29+
30+
INSERT INTO client_details (client_id, client_secret, client_name, dynamically_registered, refresh_token_validity_seconds, access_token_validity_seconds, id_token_validity_seconds, allow_introspection) select client_id, client_secret, client_name, dynamically_registered, refresh_token_validity_seconds, access_token_validity_seconds, id_token_validity_seconds, allow_introspection from client_details_TEMP
31+
ON DUPLICATE KEY UPDATE client_details.client_id=VALUES(client_id);
32+
33+
34+
INSERT INTO client_scope (owner_id, scope) SELECT id , scope FROM client_scope_TEMP, client_details WHERE client_details.client_id = client_scope_TEMP.owner_id
35+
ON DUPLICATE KEY UPDATE client_scope.owner_id = VALUES(owner_id) , client_scope.scope = VALUES(scope);
36+
37+
38+
INSERT INTO client_redirect_uri (owner_id, redirect_uri) SELECT id, redirect_uri FROM client_redirect_uri_TEMP, client_details WHERE client_details.client_id = client_redirect_uri_TEMP.owner_id
39+
ON DUPLICATE KEY UPDATE client_redirect_uri.owner_id =VALUES(owner_id) , client_redirect_uri.redirect_uri = VALUES(redirect_uri);
40+
41+
42+
INSERT INTO client_grant_type (owner_id, grant_type) SELECT id, grant_type FROM client_grant_type_TEMP, client_details WHERE client_details.client_id = client_grant_type_TEMP.owner_id
43+
ON DUPLICATE KEY UPDATE client_grant_type.owner_id=VALUES(owner_id) , client_grant_type.grant_type = VALUES(grant_type);
44+
6545

6646
COMMIT;
6747

68-
SET AUTOCOMMIT TRUE;
69-
48+
SET AUTOCOMMIT=1;
Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
--
2-
-- Turn off autocommit and start a transaction so that we can use the temp tables
3-
--
41

5-
SET AUTOCOMMIT FALSE;
2+
3+
SET AUTOCOMMIT=0;
64

75
START TRANSACTION;
86

9-
--
10-
-- Insert scope information into the temporary tables.
11-
--
7+
128

139
INSERT INTO system_scope_TEMP (scope, description, icon, restricted, default_scope, structured, structured_param_description) VALUES
1410
('openid', 'log in using your identity', 'user', false, true, false, null),
@@ -18,16 +14,9 @@ INSERT INTO system_scope_TEMP (scope, description, icon, restricted, default_sco
1814
('phone', 'telephone number', 'bell', false, true, false, null),
1915
('offline_access', 'offline access', 'time', false, false, false, null);
2016

21-
--
22-
-- Merge the temporary scopes safely into the database. This is a two-step process to keep scopes from being created on every startup with a persistent store.
23-
--
24-
25-
MERGE INTO system_scope
26-
USING (SELECT scope, description, icon, restricted, default_scope, structured, structured_param_description FROM system_scope_TEMP) AS vals(scope, description, icon, restricted, default_scope, structured, structured_param_description)
27-
ON vals.scope = system_scope.scope
28-
WHEN NOT MATCHED THEN
29-
INSERT (scope, description, icon, restricted, default_scope, structured, structured_param_description) VALUES(vals.scope, vals.description, vals.icon, vals.restricted, vals.default_scope, vals.structured, vals.structured_param_description);
17+
INSERT INTO system_scope (scope, description, icon, restricted, default_scope, structured, structured_param_description) SELECT scope, description, icon, restricted, default_scope, structured, structured_param_description FROM system_scope_TEMP
18+
ON DUPLICATE KEY UPDATE system_scope.scope=VALUES(scope);
3019

3120
COMMIT;
3221

33-
SET AUTOCOMMIT TRUE;
22+
SET AUTOCOMMIT=1;

openid-connect-server-webapp/src/main/resources/db/tables/loading_temp_tables.sql

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,62 +14,62 @@ CREATE TEMPORARY TABLE IF NOT EXISTS users_TEMP (
1414
enabled boolean not null);
1515

1616
CREATE TEMPORARY TABLE IF NOT EXISTS user_info_TEMP (
17-
sub VARCHAR(256) not null primary key,
18-
preferred_username VARCHAR(256),
19-
name VARCHAR(256),
20-
given_name VARCHAR(256),
21-
family_name VARCHAR(256),
22-
middle_name VARCHAR(256),
23-
nickname VARCHAR(256),
24-
profile VARCHAR(256),
25-
picture VARCHAR(256),
26-
website VARCHAR(256),
27-
email VARCHAR(256),
17+
sub VARCHAR(255) not null primary key,
18+
preferred_username VARCHAR(255),
19+
name VARCHAR(255),
20+
given_name VARCHAR(255),
21+
family_name VARCHAR(255),
22+
middle_name VARCHAR(255),
23+
nickname VARCHAR(255),
24+
profile VARCHAR(255),
25+
picture VARCHAR(255),
26+
website VARCHAR(255),
27+
email VARCHAR(255),
2828
email_verified BOOLEAN,
29-
gender VARCHAR(256),
30-
zone_info VARCHAR(256),
31-
locale VARCHAR(256),
32-
phone_number VARCHAR(256),
33-
address_id VARCHAR(256),
34-
updated_time VARCHAR(256),
35-
birthdate VARCHAR(256)
29+
gender VARCHAR(255),
30+
zone_info VARCHAR(255),
31+
locale VARCHAR(255),
32+
phone_number VARCHAR(255),
33+
address_id VARCHAR(255),
34+
updated_time VARCHAR(255),
35+
birthdate VARCHAR(255)
3636
);
3737

3838
CREATE TEMPORARY TABLE IF NOT EXISTS client_details_TEMP (
39-
client_description VARCHAR(256),
39+
client_description VARCHAR(255),
4040
dynamically_registered BOOLEAN,
4141
id_token_validity_seconds BIGINT,
4242

43-
client_id VARCHAR(256),
43+
client_id VARCHAR(255),
4444
client_secret VARCHAR(2048),
4545
access_token_validity_seconds BIGINT,
4646
refresh_token_validity_seconds BIGINT,
4747
allow_introspection BOOLEAN,
4848

49-
client_name VARCHAR(256)
49+
client_name VARCHAR(255)
5050
);
5151

5252
CREATE TEMPORARY TABLE IF NOT EXISTS client_scope_TEMP (
53-
owner_id VARCHAR(256),
53+
owner_id VARCHAR(255),
5454
scope VARCHAR(2048)
5555
);
5656

5757
CREATE TEMPORARY TABLE IF NOT EXISTS client_redirect_uri_TEMP (
58-
owner_id VARCHAR(256),
58+
owner_id VARCHAR(255),
5959
redirect_uri VARCHAR(2048)
6060
);
6161

6262
CREATE TEMPORARY TABLE IF NOT EXISTS client_grant_type_TEMP (
63-
owner_id VARCHAR(256),
63+
owner_id VARCHAR(255),
6464
grant_type VARCHAR(2000)
6565
);
6666

6767
CREATE TEMPORARY TABLE IF NOT EXISTS system_scope_TEMP (
68-
scope VARCHAR(256),
68+
scope VARCHAR(255),
6969
description VARCHAR(4096),
70-
icon VARCHAR(256),
70+
icon VARCHAR(255),
7171
restricted BOOLEAN,
7272
default_scope BOOLEAN,
7373
structured BOOLEAN,
74-
structured_param_description VARCHAR(256)
74+
structured_param_description VARCHAR(255)
7575
);

0 commit comments

Comments
 (0)