diff --git a/src/main/resources/db/migration/V1.0.0__init.sql b/src/main/resources/db/migration/V1.0.0__init.sql index 52420127..2dbc00f0 100644 --- a/src/main/resources/db/migration/V1.0.0__init.sql +++ b/src/main/resources/db/migration/V1.0.0__init.sql @@ -96,6 +96,11 @@ CREATE TABLE projects license_name varchar(255), license_url varchar(255), forum_sync boolean DEFAULT TRUE NOT NULL, + donation_enabled boolean default false, + donation_default_amount int default 5, + donation_email varchar(255), + donation_onetime_amounts integer[] default ARRAY[]::integer[], + donation_monthly_amounts integer[] default ARRAY[]::integer[], CONSTRAINT projects_owner_name_name_key UNIQUE (owner_name, name), CONSTRAINT projects_owner_name_slug_key @@ -346,7 +351,6 @@ CREATE TABLE user_project_roles REFERENCES projects ON DELETE CASCADE, accepted boolean DEFAULT FALSE NOT NULL, - CONSTRAINT project_roles_user_id_role_type UNIQUE (user_id, role_type), CONSTRAINT project_roles_user_id_project_id UNIQUE (user_id, project_id) ); @@ -465,7 +469,6 @@ CREATE TABLE user_organization_roles REFERENCES organizations ON DELETE CASCADE, accepted boolean default false NOT NULL, - CONSTRAINT organization_roles_user_id_role_type UNIQUE (user_id, role_type), CONSTRAINT organization_roles_user_id_organization_id UNIQUE (user_id, organization_id) ); @@ -505,8 +508,7 @@ CREATE TABLE project_version_unsafe_downloads CONSTRAINT project_version_unsafe_downloads_fkey REFERENCES users ON DELETE CASCADE, - address inet NOT NULL, - download_type integer NOT NULL + address inet NOT NULL ); CREATE TABLE project_version_download_warnings @@ -515,7 +517,7 @@ CREATE TABLE project_version_download_warnings CONSTRAINT project_version_download_warnings_pkey PRIMARY KEY, created_at timestamp with time zone NOT NULL, - expiration timestamp with time zone NOT NULL, + expires_at timestamp with time zone NOT NULL, token varchar(255) NOT NULL, version_id bigint NOT NULL CONSTRAINT project_version_download_warnings_version_id_fkey @@ -531,19 +533,6 @@ CREATE TABLE project_version_download_warnings UNIQUE (address, version_id) ); -CREATE TABLE project_api_keys -( - id bigserial NOT NULL - CONSTRAINT project_api_keys_pkey - PRIMARY KEY, - created_at timestamp with time zone NOT NULL, - project_id bigint NOT NULL - CONSTRAINT project_api_keys_project_id_fkey - REFERENCES projects - ON DELETE CASCADE, - value varchar(255) NOT NULL -); - CREATE TABLE project_version_reviews ( id bigserial NOT NULL @@ -676,28 +665,12 @@ CREATE TABLE api_keys UNIQUE, token text NOT NULL, raw_key_permissions bit(64) NOT NULL, + CONSTRAINT api_keys_owner_id_token_identifier + UNIQUE (owner_id, token_identifier), CONSTRAINT api_keys_owner_id_name_key UNIQUE (owner_id, name) ); -CREATE TABLE api_sessions -( - id bigserial NOT NULL - constraint api_sessions_pkey - primary key, - created_at timestamp with time zone NOT NULL, - token varchar(255) NOT NULL, - key_id bigint - constraint api_sessions_key_id_fkey - references api_keys - ON DELETE CASCADE, - user_id bigint - constraint api_sessions_user_id_fkey - references users - ON DELETE CASCADE, - expires timestamp with time zone NOT NULL -); - CREATE TABLE logged_actions_project ( id bigserial NOT NULL @@ -910,6 +883,15 @@ CREATE TABLE user_refresh_tokens device_id uuid NOT NULL CONSTRAINT user_refresh_tokens_device_id_unique UNIQUE ); +CREATE TABLE user_oauth_token( + id bigserial NOT NULL + CONSTRAINT user_oauth_token_pkey + PRIMARY KEY, + created_at timestamp with time zone NOT NULL, + username varchar(255), + id_token text +); + CREATE INDEX user_refresh_tokens_token_idx ON user_refresh_tokens (token); CREATE VIEW project_members_all(id, user_id) AS @@ -1059,8 +1041,7 @@ FROM organization_members om ON om.organization_id = ro.organization_id AND om.user_id = ro.user_id AND ro.accepted JOIN roles r ON ro.role_type::text = r.name::text GROUP BY om.organization_id, om.user_id; - -CREATE VIEW v_logged_actions(id, created_at, user_id, user_name, address, action, context_type, new_state, old_state, p_id, p_slug, p_owner_name, pv_id, pv_version_string, pp_id, pp_name, pp_slug, s_id, s_name) AS +CREATE VIEW v_logged_actions(id, created_at, user_id, user_name, address, action, context_type, new_state, old_state, p_id, p_slug, p_owner_name, pv_id, pv_version_string, pv_platforms, pp_id, pp_name, pp_slug, s_id, s_name) AS SELECT a.id, a.created_at, a.user_id, @@ -1075,6 +1056,7 @@ SELECT a.id, ou.name AS p_owner_name, NULL::bigint AS pv_id, NULL::character varying(255) AS pv_version_string, + NULL::bigint[] AS pv_platforms, NULL::bigint AS pp_id, NULL::character varying(255) AS pp_name, NULL::character varying(255) AS pp_slug, @@ -1099,6 +1081,12 @@ SELECT a.id, ou.name AS p_owner_name, pv.id AS pv_id, pv.version_string AS pv_version_string, + array(SELECT DISTINCT plv.platform + FROM project_version_platform_dependencies pvpd + JOIN platform_versions plv ON pvpd.platform_version_id = plv.id + WHERE pv.id = pvpd.version_id + ORDER BY plv.platform + ) AS pv_platforms, NULL::bigint AS pp_id, NULL::character varying AS pp_name, NULL::character varying AS pp_slug, @@ -1124,6 +1112,7 @@ SELECT a.id, ou.name AS p_owner_name, NULL::bigint AS pv_id, NULL::character varying AS pv_version_string, + NULL::bigint[] AS pv_platforms, pp.id AS pp_id, pp.name AS pp_name, pp.slug AS pp_slug, @@ -1149,6 +1138,7 @@ SELECT a.id, NULL::character varying AS p_owner_name, NULL::bigint AS pv_id, NULL::character varying AS pv_version_string, + NULL::bigint[] AS pv_platforms, NULL::bigint AS pp_id, NULL::character varying AS pp_name, NULL::character varying AS pp_slug, @@ -1172,6 +1162,7 @@ SELECT a.id, NULL::character varying AS p_owner_name, NULL::bigint AS pv_id, NULL::character varying AS pv_version_string, + NULL::bigint[] AS pv_platforms, NULL::bigint AS pp_id, NULL::character varying AS pp_name, NULL::character varying AS pp_slug, diff --git a/src/main/resources/db/migration/V1.1.0__apiKeyFunctionality.sql b/src/main/resources/db/migration/V1.1.0__apiKeyFunctionality.sql deleted file mode 100644 index d490283e..00000000 --- a/src/main/resources/db/migration/V1.1.0__apiKeyFunctionality.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE api_keys ADD CONSTRAINT api_keys_owner_id_token_identifier UNIQUE (owner_id, token_identifier); - -DROP TABLE api_sessions; diff --git a/src/main/resources/db/migration/V1.2.0__donationSettings.sql b/src/main/resources/db/migration/V1.2.0__donationSettings.sql deleted file mode 100644 index f084f085..00000000 --- a/src/main/resources/db/migration/V1.2.0__donationSettings.sql +++ /dev/null @@ -1,14 +0,0 @@ -alter table projects - add donation_enabled boolean default false; - -alter table projects - add donation_default_amount int default 5; - -alter table projects - add donation_email varchar(255); - -alter table projects - add donation_onetime_amounts integer[] default ARRAY[]::integer[]; - -alter table projects - add donation_monthly_amounts integer[] default ARRAY[]::integer[]; diff --git a/src/main/resources/db/migration/V1.3.0__fixRoleConstraints.sql b/src/main/resources/db/migration/V1.3.0__fixRoleConstraints.sql deleted file mode 100644 index 0a8efb4f..00000000 --- a/src/main/resources/db/migration/V1.3.0__fixRoleConstraints.sql +++ /dev/null @@ -1,3 +0,0 @@ -DROP INDEX user_project_roles@project_roles_user_id_role_type CASCADE; - -DROP INDEX user_organization_roles@organization_roles_user_id_role_type CASCADE; diff --git a/src/main/resources/db/migration/V1.4.0__addTokentoUnsafeDownloads.sql b/src/main/resources/db/migration/V1.4.0__addTokentoUnsafeDownloads.sql deleted file mode 100644 index 0790d422..00000000 --- a/src/main/resources/db/migration/V1.4.0__addTokentoUnsafeDownloads.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE project_version_unsafe_downloads DROP COLUMN download_type; - -ALTER TABLE project_version_download_warnings RENAME expiration TO expiresAt; diff --git a/src/main/resources/db/migration/V1.4.1__didADumWithNewName.sql b/src/main/resources/db/migration/V1.4.1__didADumWithNewName.sql deleted file mode 100644 index 74a1ad23..00000000 --- a/src/main/resources/db/migration/V1.4.1__didADumWithNewName.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE project_version_download_warnings RENAME expiresat TO expires_at; diff --git a/src/main/resources/db/migration/V1.5.0__addVersionPlatformToLoggedActions.sql b/src/main/resources/db/migration/V1.5.0__addVersionPlatformToLoggedActions.sql deleted file mode 100644 index 1a9511ed..00000000 --- a/src/main/resources/db/migration/V1.5.0__addVersionPlatformToLoggedActions.sql +++ /dev/null @@ -1,132 +0,0 @@ -DROP VIEW IF EXISTS v_logged_actions; -CREATE VIEW v_logged_actions(id, created_at, user_id, user_name, address, action, context_type, new_state, old_state, p_id, p_slug, p_owner_name, pv_id, pv_version_string, pv_platforms, pp_id, pp_name, pp_slug, s_id, s_name) AS -SELECT a.id, - a.created_at, - a.user_id, - u.name AS user_name, - a.address, - a.action, - 0 AS context_type, - a.new_state, - a.old_state, - p.id AS p_id, - p.slug AS p_slug, - ou.name AS p_owner_name, - NULL::bigint AS pv_id, - NULL::character varying(255) AS pv_version_string, - NULL::bigint[] AS pv_platforms, - NULL::bigint AS pp_id, - NULL::character varying(255) AS pp_name, - NULL::character varying(255) AS pp_slug, - NULL::bigint AS s_id, - NULL::character varying(255) AS s_name -FROM logged_actions_project a - LEFT JOIN users u ON a.user_id = u.id - LEFT JOIN projects p ON a.project_id = p.id - LEFT JOIN users ou ON p.owner_id = ou.id -UNION ALL -SELECT a.id, - a.created_at, - a.user_id, - u.name AS user_name, - a.address, - a.action, - 1 AS context_type, - a.new_state, - a.old_state, - p.id AS p_id, - p.slug AS p_slug, - ou.name AS p_owner_name, - pv.id AS pv_id, - pv.version_string AS pv_version_string, - array(SELECT DISTINCT plv.platform - FROM project_version_platform_dependencies pvpd - JOIN platform_versions plv ON pvpd.platform_version_id = plv.id - WHERE pv.id = pvpd.version_id - ORDER BY plv.platform - ) AS pv_platforms, - NULL::bigint AS pp_id, - NULL::character varying AS pp_name, - NULL::character varying AS pp_slug, - NULL::bigint AS s_id, - NULL::character varying AS s_name -FROM logged_actions_version a - LEFT JOIN users u ON a.user_id = u.id - LEFT JOIN project_versions pv ON a.version_id = pv.id - LEFT JOIN projects p ON a.project_id = p.id - LEFT JOIN users ou ON p.owner_id = ou.id -UNION ALL -SELECT a.id, - a.created_at, - a.user_id, - u.name AS user_name, - a.address, - a.action, - 2 AS context_type, - a.new_state, - a.old_state, - p.id AS p_id, - p.slug AS p_slug, - ou.name AS p_owner_name, - NULL::bigint AS pv_id, - NULL::character varying AS pv_version_string, - NULL::bigint[] AS pv_platforms, - pp.id AS pp_id, - pp.name AS pp_name, - pp.slug AS pp_slug, - NULL::bigint AS s_id, - NULL::character varying AS s_name -FROM logged_actions_page a - LEFT JOIN users u ON a.user_id = u.id - LEFT JOIN project_pages pp ON a.page_id = pp.id - LEFT JOIN projects p ON a.project_id = p.id - LEFT JOIN users ou ON p.owner_id = ou.id -UNION ALL -SELECT a.id, - a.created_at, - a.user_id, - u.name AS user_name, - a.address, - a.action, - 3 AS context_type, - a.new_state, - a.old_state, - NULL::bigint AS p_id, - NULL::character varying AS p_slug, - NULL::character varying AS p_owner_name, - NULL::bigint AS pv_id, - NULL::character varying AS pv_version_string, - NULL::bigint[] AS pv_platforms, - NULL::bigint AS pp_id, - NULL::character varying AS pp_name, - NULL::character varying AS pp_slug, - s.id AS s_id, - s.name AS s_name -FROM logged_actions_user a - LEFT JOIN users u ON a.user_id = u.id - LEFT JOIN users s ON a.subject_id = s.id -UNION ALL -SELECT a.id, - a.created_at, - a.user_id, - u.name AS user_name, - a.address, - a.action, - 4 AS context_type, - a.new_state, - a.old_state, - NULL::bigint AS p_id, - NULL::character varying AS p_slug, - NULL::character varying AS p_owner_name, - NULL::bigint AS pv_id, - NULL::character varying AS pv_version_string, - NULL::bigint[] AS pv_platforms, - NULL::bigint AS pp_id, - NULL::character varying AS pp_name, - NULL::character varying AS pp_slug, - s.id AS s_id, - s.name AS s_name -FROM logged_actions_organization a - LEFT JOIN organizations o ON a.organization_id = o.id - LEFT JOIN users u ON a.user_id = u.id - LEFT JOIN users s ON o.user_id = s.id; diff --git a/src/main/resources/db/migration/V1.6.0__saveIdToken.sql b/src/main/resources/db/migration/V1.6.0__saveIdToken.sql deleted file mode 100644 index bf06bb88..00000000 --- a/src/main/resources/db/migration/V1.6.0__saveIdToken.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE user_oauth_token( - id bigserial NOT NULL - CONSTRAINT user_oauth_token_pkey - PRIMARY KEY, - created_at timestamp with time zone NOT NULL, - username varchar(255), - id_token text -) diff --git a/src/main/resources/db/migration/V1.7.0__deleteProjectsApiKeysTable.sql b/src/main/resources/db/migration/V1.7.0__deleteProjectsApiKeysTable.sql deleted file mode 100644 index 54726bfb..00000000 --- a/src/main/resources/db/migration/V1.7.0__deleteProjectsApiKeysTable.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE project_api_keys;