scope bootstrapping

pull/306/merge
Justin Richer 2013-02-05 15:08:49 -05:00
parent 02846c0a8d
commit 328fa221bd
5 changed files with 47 additions and 3 deletions

View File

@ -0,0 +1,34 @@
--
-- Turn off autocommit and start a transaction so that we can use the temp tables
--
SET AUTOCOMMIT FALSE;
START TRANSACTION;
--
-- Insert scope information into the temporary tables.
--
INSERT INTO system_scope_TEMP (scope, description, icon, allow_dyn_reg, default_scope) VALUES
('openid', 'log in using your identity', 'user', true, true),
('profile', 'basic profile information', 'list-alt', true, true),
('email', 'email address', 'envelope', true, true),
('address', 'physical address', 'home', true, true),
('phone', 'telephone number', 'bell', true, true),
('offline_access', 'offline access', 'time', true, true);
--
-- 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.
--
MERGE INTO system_scope
USING (SELECT scope, description, icon, allow_dyn_reg, default_scope FROM system_scope_TEMP) AS vals(scope, description, icon, allow_dyn_reg, default_scope)
ON vals.scope = system_scope.scope
WHEN NOT MATCHED THEN
INSERT (scope, description, icon, allow_dyn_reg, default_scope) VALUES(vals.scope, vals.description, vals.icon, vals.allow_dyn_reg, vals.default_scope);
COMMIT;
SET AUTOCOMMIT TRUE;

View File

@ -162,12 +162,12 @@ CREATE TABLE IF NOT EXISTS token_scope (
CREATE TABLE IF NOT EXISTS system_scope (
id BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) PRIMARY KEY,
scope VARCHAR(1024) NOT NULL,
scope VARCHAR(256) NOT NULL,
description VARCHAR(4096),
icon VARCHAR(256),
allow_dyn_reg BOOLEAN NOT NULL DEFAULT false,
default_scope BOOLEAN NOT NULL DEFAULT false,
UNIQUE scope
UNIQUE (scope)
);
CREATE TABLE IF NOT EXISTS user_info (

View File

@ -64,3 +64,11 @@ CREATE TEMPORARY TABLE IF NOT EXISTS authorized_grant_type_TEMP (
owner_id VARCHAR(256),
authorized_grant_type VARCHAR(2000)
);
CREATE TEMPORARY TABLE IF NOT EXISTS system_scope_TEMP (
scope VARCHAR(256),
description VARCHAR(4096),
icon VARCHAR(256),
allow_dyn_reg BOOLEAN,
default_scope BOOLEAN
);

View File

@ -157,11 +157,12 @@ CREATE TABLE token_scope (
CREATE TABLE system_scope (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
scope VARCHAR(1024) UNIQUE NOT NULL,
scope VARCHAR(256) NOT NULL,
description VARCHAR(4096),
icon VARCHAR(256),
allow_dyn_reg BOOLEAN NOT NULL DEFAULT 0,
default_scope BOOLEAN NOT NULL DEFAULT 0,
unique(scope)
);

View File

@ -23,6 +23,7 @@
<jdbc:script location="classpath:/db/tables/loading_temp_tables.sql"/>
<jdbc:script location="classpath:/db/users.sql"/>
<jdbc:script location="classpath:/db/clients.sql"/>
<jdbc:script location="classpath:/db/scopes.sql"/>
</jdbc:initialize-database>
<bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">