add db init script for mysql

add data-context example with mysql db initializer
pull/1079/merge
Neths 8 years ago committed by Justin Richer
parent cbe6b9e1df
commit 1b7612a26d

@ -0,0 +1,61 @@
--
-- Turn off autocommit and start a transaction so that we can use the temp tables
--
SET AUTOCOMMIT = 0;
START TRANSACTION;
--
-- Insert client information into the temporary tables. To add clients to the HSQL database, edit things here.
--
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
('client', 'secret', 'Test Client', false, null, 3600, 600, true);
INSERT INTO client_scope_TEMP (owner_id, scope) VALUES
('client', 'openid'),
('client', 'profile'),
('client', 'email'),
('client', 'address'),
('client', 'phone'),
('client', 'offline_access');
INSERT INTO client_redirect_uri_TEMP (owner_id, redirect_uri) VALUES
('client', 'http://localhost/'),
('client', 'http://localhost:8080/');
INSERT INTO client_grant_type_TEMP (owner_id, grant_type) VALUES
('client', 'authorization_code'),
('client', 'urn:ietf:params:oauth:grant_type:redelegate'),
('client', 'implicit'),
('client', 'refresh_token');
--
-- 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.
--
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
ON DUPLICATE KEY UPDATE client_details.client_id = client_details.client_id;
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
ON DUPLICATE KEY UPDATE client_scope.owner_id = client_scope.owner_id;
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
ON DUPLICATE KEY UPDATE client_redirect_uri.owner_id = client_redirect_uri.owner_id;
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
ON DUPLICATE KEY UPDATE client_grant_type.owner_id = client_grant_type.owner_id;
--
-- Close the transaction and turn autocommit back on
--
COMMIT;
SET AUTOCOMMIT = 1;

@ -0,0 +1,31 @@
--
-- Turn off autocommit and start a transaction so that we can use the temp tables
--
SET AUTOCOMMIT = 0;
START TRANSACTION;
--
-- Insert scope information into the temporary tables.
--
INSERT INTO system_scope_TEMP (scope, description, icon, restricted, default_scope, structured, structured_param_description) VALUES
('openid', 'log in using your identity', 'user', false, true, false, null),
('profile', 'basic profile information', 'list-alt', false, true, false, null),
('email', 'email address', 'envelope', false, true, false, null),
('address', 'physical address', 'home', false, true, false, null),
('phone', 'telephone number', 'bell', false, true, false, null),
('offline_access', 'offline access', 'time', false, false, false, null);
--
-- 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.
--
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
ON DUPLICATE KEY UPDATE system_scope.scope = system_scope.scope;
COMMIT;
SET AUTOCOMMIT = 1;

@ -0,0 +1,52 @@
--
-- Turn off autocommit and start a transaction so that we can use the temp tables
--
SET AUTOCOMMIT = 0;
START TRANSACTION;
--
-- Insert user information into the temporary tables. To add users to the HSQL database, edit things here.
--
INSERT INTO users_TEMP (username, password, enabled) VALUES
('admin','password',true),
('user','password',true);
INSERT INTO authorities_TEMP (username, authority) VALUES
('admin','ROLE_ADMIN'),
('admin','ROLE_USER'),
('user','ROLE_USER');
-- By default, the username column here has to match the username column in the users table, above
INSERT INTO user_info_TEMP (sub, preferred_username, name, email, email_verified) VALUES
('90342.ASDFJWFA','admin','Demo Admin','admin@example.com', true),
('01921.FLANRJQW','user','Demo User','user@example.com', true);
--
-- Merge the temporary users safely into the database. This is a two-step process to keep users from being created on every startup with a persistent store.
--
INSERT INTO users (username, password, enabled)
SELECT username, password, enabled FROM users_TEMP
ON DUPLICATE KEY UPDATE users.username = users.username;
INSERT INTO authorities (username,authority)
SELECT username, authority FROM authorities_TEMP
ON DUPLICATE KEY UPDATE authorities.username = authorities.username;
INSERT INTO user_info (sub, preferred_username, name, email, email_verified)
SELECT sub, preferred_username, name, email, email_verified FROM user_info_TEMP
ON DUPLICATE KEY UPDATE user_info.preferred_username = user_info.preferred_username;
--
-- Close the transaction and turn autocommit back on
--
COMMIT;
SET AUTOCOMMIT = 1;

@ -49,20 +49,26 @@
<!-- The following is for connecting to a MySQL database that has been initialized with
src/main/resources/db/tables/mysql_database_tables.sql -->
<!--
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost/oic" />
<!--<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/oic" />
<property name="username" value="oic" />
<property name="password" value="oic" />
<property name="password" value="oic" />
</bean>
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="classpath:/db/tables/mysql_database_tables.sql"/>
<jdbc:script location="classpath:/db/tables/security-schema.sql"/>
<jdbc:script location="classpath:/db/tables/loading_temp_tables.sql"/>
<jdbc:script location="classpath:/db/mysql/users.sql"/>
<jdbc:script location="classpath:/db/mysql/clients.sql"/>
<jdbc:script location="classpath:/db/mysql/scopes.sql"/>
</jdbc:initialize-database>
<bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<property name="databasePlatform" value="org.eclipse.persistence.platform.database.MySQLPlatform" />
<property name="showSql" value="true" />
</bean>
-->
</bean> -->
<!-- The following is for connecting to a PostgreSQL database that has been initialized with
src/main/resources/db/tables/psql_database_tables.sql -->

Loading…
Cancel
Save