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

🔧 MAINTAIN: Add verdi devel run-sql #5094

Merged
merged 2 commits into from
Aug 25, 2021
Merged

🔧 MAINTAIN: Add verdi devel run-sql #5094

merged 2 commits into from
Aug 25, 2021

Conversation

chrisjsewell
Copy link
Member

For quickly running raw SQL commands on the database

@chrisjsewell chrisjsewell requested a review from sphuber August 24, 2021 14:54
@chrisjsewell
Copy link
Member Author

chrisjsewell commented Aug 24, 2021

So I can quickly do things like inspecting the schema:

$ verdi devel run-sql "SELECT * FROM information_schema.tables WHERE table_schema = 'public'"
('new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'public', 'django_migrations', 'BASE TABLE', None, None, None, None, None, 'YES', 'NO', None)
('new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'public', 'django_content_type', 'BASE TABLE', None, None, None, None, None, 'YES', 'NO', None)
('new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'public', 'auth_permission', 'BASE TABLE', None, None, None, None, None, 'YES', 'NO', None)
('new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'public', 'auth_group', 'BASE TABLE', None, None, None, None, None, 'YES', 'NO', None)
('new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'public', 'auth_group_permissions', 'BASE TABLE', None, None, None, None, None, 'YES', 'NO', None)
('new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'public', 'db_dbsetting', 'BASE TABLE', None, None, None, None, None, 'YES', 'NO', None)
('new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'public', 'db_dblog', 'BASE TABLE', None, None, None, None, None, 'YES', 'NO', None)
('new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'public', 'db_dbuser', 'BASE TABLE', None, None, None, None, None, 'YES', 'NO', None)
('new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'public', 'db_dbauthinfo', 'BASE TABLE', None, None, None, None, None, 'YES', 'NO', None)
('new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'public', 'db_dbgroup_dbnodes', 'BASE TABLE', None, None, None, None, None, 'YES', 'NO', None)
('new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'public', 'db_dbcomputer', 'BASE TABLE', None, None, None, None, None, 'YES', 'NO', None)
('new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'public', 'db_dbgroup', 'BASE TABLE', None, None, None, None, None, 'YES', 'NO', None)
('new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'public', 'db_dbnode', 'BASE TABLE', None, None, None, None, None, 'YES', 'NO', None)
('new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'public', 'db_dblink', 'BASE TABLE', None, None, None, None, None, 'YES', 'NO', None)
('new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'public', 'db_dbcomment', 'BASE TABLE', None, None, None, None, None, 'YES', 'NO', None)

(https://www.postgresql.org/docs/current/infoschema-tables.html)

$ verdi devel run-sql "SELECT * FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'db_dbcomment'"
('new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'public', 'db_dbcomment', 'id', 1, "nextval('db_dbcomment_id_seq'::regclass)", 'NO', 'integer', None, None, 32, 2, 0, None, None, None, None, None, None, None, None, None, None, None, None, 'new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'pg_catalog', 'int4', None, None, None, None, '1', 'NO', 'NO', None, None, None, None, None, 'NO', 'NEVER', None, 'YES')
('new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'public', 'db_dbcomment', 'uuid', 2, None, 'NO', 'uuid', None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, 'new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'pg_catalog', 'uuid', None, None, None, None, '2', 'NO', 'NO', None, None, None, None, None, 'NO', 'NEVER', None, 'YES')
('new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'public', 'db_dbcomment', 'ctime', 3, None, 'NO', 'timestamp with time zone', None, None, None, None, None, 6, None, None, None, None, None, None, None, None, None, None, None, 'new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'pg_catalog', 'timestamptz', None, None, None, None, '3', 'NO', 'NO', None, None, None, None, None, 'NO', 'NEVER', None, 'YES')
('new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'public', 'db_dbcomment', 'mtime', 4, None, 'NO', 'timestamp with time zone', None, None, None, None, None, 6, None, None, None, None, None, None, None, None, None, None, None, 'new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'pg_catalog', 'timestamptz', None, None, None, None, '4', 'NO', 'NO', None, None, None, None, None, 'NO', 'NEVER', None, 'YES')
('new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'public', 'db_dbcomment', 'content', 5, None, 'NO', 'text', None, 1073741824, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, 'new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'pg_catalog', 'text', None, None, None, None, '5', 'NO', 'NO', None, None, None, None, None, 'NO', 'NEVER', None, 'YES')
('new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'public', 'db_dbcomment', 'dbnode_id', 6, None, 'NO', 'integer', None, None, 32, 2, 0, None, None, None, None, None, None, None, None, None, None, None, None, 'new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'pg_catalog', 'int4', None, None, None, None, '6', 'NO', 'NO', None, None, None, None, None, 'NO', 'NEVER', None, 'YES')
('new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'public', 'db_dbcomment', 'user_id', 7, None, 'NO', 'integer', None, None, 32, 2, 0, None, None, None, None, None, None, None, None, None, None, None, None, 'new_chrisjsewell_3abef2c96e126c712c1d3e256a3590b9', 'pg_catalog', 'int4', None, None, None, None, '7', 'NO', 'NO', None, None, None, None, None, 'NO', 'NEVER', None, 'YES')

(https://www.postgresql.org/docs/current/infoschema-columns.html)

@codecov
Copy link

codecov bot commented Aug 24, 2021

Codecov Report

Merging #5094 (4e322ce) into develop (74d8b6c) will increase coverage by 0.02%.
The diff coverage is 90.91%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #5094      +/-   ##
===========================================
+ Coverage    80.55%   80.56%   +0.02%     
===========================================
  Files          532      532              
  Lines        36999    37010      +11     
===========================================
+ Hits         29799    29814      +15     
+ Misses        7200     7196       -4     
Flag Coverage Δ
django 75.24% <90.91%> (+0.01%) ⬆️
sqlalchemy 74.25% <90.91%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aiida/cmdline/commands/cmd_devel.py 40.75% <90.91%> (+12.84%) ⬆️
aiida/transports/plugins/local.py 81.41% <0.00%> (-0.25%) ⬇️
aiida/orm/implementation/sqlalchemy/backend.py 97.57% <0.00%> (+7.32%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 74d8b6c...4e322ce. Read the comment docs.

@sphuber
Copy link
Contributor

sphuber commented Aug 24, 2021

I can already see the troubleshooting advice in the future:

To fix the problem, simply run `verdi devel run-sql "TRUNCATE db_dbnode;"

😅

BTW: why do you label this as "maintain"? Isn't this really a future, even though mostly for developers?

@chrisjsewell
Copy link
Member Author

To fix the problem, simply run `verdi devel run-sql "TRUNCATE db_dbnode;"

haha, can always hide the command, if you think it is too "dangerous" lol?

BTW: why do you label this as "maintain"?

yeh for me its not a user feature, so it goes under maintenance, i.e. when I create a changelog section next I would not put it in the "new" section.

@sphuber
Copy link
Contributor

sphuber commented Aug 24, 2021

haha, can always hide the command, if you think it is too "dangerous" lol?

Given that its under devel I think that is good enough. The one thing I would add is a quick test. I can add one tomorrow morning if you'd like and merge it straight after.

chrisjsewell and others added 2 commits August 25, 2021 07:42
Copy link
Contributor

@sphuber sphuber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hope that given it is under verdi devel users will realize this does not come with protection against shooting-yourself-in-the-foot 😄

@sphuber sphuber merged commit eae3c50 into develop Aug 25, 2021
@sphuber sphuber deleted the add-run-sql branch August 25, 2021 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants