Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL queries #370

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions scripts/GetAuthorizationIdResults.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
CREATE PROCEDURE GetAuthorizationIdResults()
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE current_table VARCHAR(255);
DECLARE row_count INT DEFAULT 0;

-- Declare a cursor to fetch all tables with the 'authorizationId' column
DECLARE table_cursor CURSOR FOR
SELECT table_name
FROM information_schema.columns
WHERE table_schema = DATABASE()
AND column_name = 'authorizationId';

-- Handler for the cursor to exit the loop
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

-- Create a temporary table to store the results
CREATE TEMPORARY TABLE IF NOT EXISTS temp_results (
table_name VARCHAR(255),
row_data TEXT
);

-- Open the cursor
OPEN table_cursor;

-- Loop through each table with the 'authorizationId' column
read_loop: LOOP
FETCH table_cursor INTO current_table;
IF done THEN
LEAVE read_loop;
END IF;

-- Construct the dynamic query to count rows where authorizationId is NULL or empty
SET @dynamic_count_query = CONCAT('SELECT COUNT(*) INTO @row_count FROM ', current_table,
' WHERE authorizationId IS NULL OR authorizationId = '''';');

-- Prepare and execute the query to count the rows
PREPARE stmt_count FROM @dynamic_count_query;
EXECUTE stmt_count;
DEALLOCATE PREPARE stmt_count;

-- Only proceed if there are rows found
IF @row_count > 0 THEN
-- Construct the dynamic query to fetch results and insert into the temporary table
SET @dynamic_query = CONCAT('INSERT INTO temp_results (table_name, row_data) ',
'SELECT ''', current_table, ''', CONCAT_WS('' | '', ', current_table, '.*) ',
'FROM ', current_table,
' WHERE authorizationId IS NULL OR authorizationId = '''';');

-- Prepare and execute the query to insert into the temp table
PREPARE stmt FROM @dynamic_query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
END LOOP;

-- Close the cursor
CLOSE table_cursor;

-- Return all accumulated results from the temporary table
SELECT * FROM temp_results;

-- Clean up: Drop the temporary table after use
DROP TEMPORARY TABLE IF EXISTS temp_results;

END
7 changes: 7 additions & 0 deletions scripts/check-accounts-agents-moved-to-space agents.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SELECT distinct(cr.resourceID), sp.nameID,sp.agentId as spaceAgent,cr.agentId as credentialAgent,
acc.agentId as accountAgent, sp.id as spaceId, cr.resourceID, acc.id as accountId ##, cr.type
FROM alkemio.account as acc
join alkemio.space as sp on (acc.id = sp.accountId)
join alkemio.credential as cr on (cr.agentId = acc.agentId or sp.agentId = cr.agentId)

where sp.level = 0 ##sp.agentId = cr.agentId
58 changes: 58 additions & 0 deletions scripts/check-for-meaningless-results.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
SELECT * FROM alkemio.organization where accountId is null; ## expected 0 results
SELECT * FROM alkemio.user where accountId is null; ## expected 0 results
SELECT * FROM alkemio.space where accountId is null and level = 0; ## expected 0 results
SELECT * FROM alkemio.space where accountId is not null and (level = 1 or level = 2); ## expected 0 results
SELECT * FROM alkemio.credential where type in('account-host'); ## expected 0 results
SELECT * FROM alkemio.space where levelZeroSpaceID is null; ## expected 0 results
SELECT * FROM alkemio.agent where type is null; ## expected 0 results
SELECT id, createdDate, nameID, level, parentSpaceId, levelZeroSpaceID FROM alkemio.space where level =1 and parentSpaceId is null; ## expected 0 results

SELECT email, credentialRules, authorizationId FROM alkemio.authorization_policy
join user on authorization_policy.id = user.authorizationId
where credentialRules = '';

SELECT nameID, credentialRules, authorizationId FROM alkemio.authorization_policy
join organization on authorization_policy.id = organization.authorizationId
where credentialRules = '';

SELECT credentialRules, authorizationId FROM alkemio.authorization_policy
join account on authorization_policy.id = account.authorizationId
where credentialRules = '';

SELECT nameID, authorizationId FROM alkemio.authorization_policy
join virtual_contributor on authorization_policy.id = virtual_contributor.authorizationId
where credentialRules = '';

SELECT nameID, authorizationId FROM alkemio.authorization_policy
join callout on authorization_policy.id = callout.authorizationId
where credentialRules = '';

SELECT nameID, authorizationId FROM alkemio.authorization_policy
join space on authorization_policy.id = space.authorizationId
where credentialRules = '';


SELECT * FROM alkemio.credential where
(type = 'space-lead' or type = 'space-member'or type ='license-space-free'or type ='organization-associate'or type ='organization-admin'
or type ='subspace-admin'or type ='user-self'or type ='space-admin'or type ='account-host'or type ='feature-callout-to-callout-template'
or type ='space-subspace-admin'or type ='feature-virtual-contributors'or type ='organization-owner'or type ='license-space-plus'
or type ='feature-whiteboard-multi-user'or type ='user-group-member'or type ='license-space-premium') and (resourceID like '' and resourceID is null);## expected 0 results

SELECT * FROM alkemio.credential where
(type ='vc-campaign'
or type = 'global-admin'
or type = 'global-support'
or type = 'global-community-read'
or type = 'global-registered'
or type = 'global-license-manager'
or type = 'beta-tester') and
(resourceID not like '' and resourceID is not null) ; ## expected 0 results


SELECT distinct(cr.resourceID), sp.nameID,sp.agentId as spaceAgent,cr.agentId as credentialAgent,
acc.agentId as accountAgent, sp.id as spaceId, cr.resourceID, acc.id as accountId ##, cr.type
FROM alkemio.account as acc
join alkemio.space as sp on (acc.id = sp.accountId)
join alkemio.credential as cr on (cr.agentId = acc.agentId or sp.agentId = cr.agentId)

where sp.level = 0 ##sp.agentId = cr.agentId
28 changes: 28 additions & 0 deletions scripts/getAllTablesAuthorizationIdCheck.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CREATE PROCEDURE getAllTablesAuthorizationIdCheck()
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE tbl_name VARCHAR(255);
DECLARE cur CURSOR FOR
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'your_database_name'; -- Replace with your actual database name

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

OPEN cur;

read_loop: LOOP
FETCH cur INTO tbl_name;
IF done THEN
LEAVE read_loop;
END IF;

SET @query = CONCAT('SELECT * FROM ', tbl_name, ' WHERE (NOT EXISTS (SELECT 1 FROM authorization_policy WHERE authorization_policy.id = ', tbl_name, '.authorizationId) OR ', tbl_name, '.authorizationId IS NULL)');

PREPARE stmt FROM @query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END LOOP;

CLOSE cur;
END
4 changes: 4 additions & 0 deletions scripts/orphaned/account.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT * FROM alkemio.account;
SELECT * FROM alkemio.account where type = '' or type is null;
SELECT * FROM alkemio.account where agentId = '' or agentId is null;
SELECT * FROM alkemio.account where authorizationId = '' or authorizationId is null;
10 changes: 10 additions & 0 deletions scripts/orphaned/activity.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SELECT * FROM alkemio.activity;
SELECT * FROM alkemio.activity where triggeredBy = '' or triggeredBy is null;
SELECT * FROM alkemio.activity where collaborationID = '' or collaborationID is null ;
SELECT * FROM alkemio.activity where resourceID = '' or resourceID is null;
SELECT * FROM alkemio.activity where description = '' or description is null;
SELECT * FROM alkemio.activity where type = '' or type is null;
SELECT * FROM alkemio.activity where (parentID = '' or parentID is null);

SELECT * FROM alkemio.activity where (messageID = '' or messageId is null) and (type = 'post-comment' or type = 'discussion-comment');
SELECT * FROM alkemio.activity where visibility = '' or visibility is null;
3 changes: 3 additions & 0 deletions scripts/orphaned/agent.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT * FROM alkemio.agent;
SELECT * FROM alkemio.agent where authorizationId = '' or authorizationId is null;
SELECT * FROM alkemio.agent where type = '' or type is null;
6 changes: 6 additions & 0 deletions scripts/orphaned/ai_persona.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT * FROM alkemio.ai_persona;
SELECT * FROM alkemio.ai_persona where description = '' or description is null;
SELECT * FROM alkemio.ai_persona where authorizationId = '' or authorizationId is null;
SELECT * FROM alkemio.ai_persona where interactionModes = '' or interactionModes is null;
SELECT * FROM alkemio.ai_persona where dataAccessMode = '' or dataAccessMode is null;
SELECT * FROM alkemio.ai_persona where bodyOfKnowledge = '' or bodyOfKnowledge is null;
11 changes: 11 additions & 0 deletions scripts/orphaned/ai_persona_service.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SELECT * FROM alkemio.ai_persona_service;
SELECT * FROM alkemio.ai_persona_service where engine = '' or engine is null;
SELECT * FROM alkemio.ai_persona_service where dataAccessMode = '' or dataAccessMode is null;
SELECT * FROM alkemio.ai_persona_service where prompt = '' or prompt is null;
SELECT * FROM alkemio.ai_persona_service where bodyOfKnowledgeID = '' or bodyOfKnowledgeID is null;
SELECT * FROM alkemio.ai_persona_service where bodyOfKnowledgeType = '' or bodyOfKnowledgeType is null;
SELECT * FROM alkemio.ai_persona_service where bodyOfKnowledgeLastUpdated is null;
SELECT * FROM alkemio.ai_persona_service where authorizationId = '' or authorizationId is null;
SELECT * FROM alkemio.ai_persona_service where aiServerId = '' or aiServerId is null;


5 changes: 5 additions & 0 deletions scripts/orphaned/application.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT * FROM alkemio.application;
SELECT * FROM alkemio.application where authorizationId = '' or authorizationId is null;
SELECT * FROM alkemio.application where lifecycleId = '' or lifecycleId is null;
SELECT * FROM alkemio.application where userId = '' or userId is null;
SELECT * FROM alkemio.application where communityId = '' or communityId is null;
5 changes: 5 additions & 0 deletions scripts/orphaned/authorization_policy.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT * FROM alkemio.authorization_policy;
SELECT * FROM alkemio.authorization_policy where credentialRules = '' or credentialRules is null;
SELECT * FROM alkemio.authorization_policy where anonymousReadAccess = '' or anonymousReadAccess is null;
SELECT * FROM alkemio.authorization_policy where privilegeRules = '' or privilegeRules is null;
SELECT * FROM alkemio.authorization_policy where type = '' or type is null;
Loading