Skip to content

Commit a344e14

Browse files
Geogouzrdimaio
authored andcommitted
Database: Remove destroy_database.py and adjust reset_database.py for its replacement.
1 parent 8917fcd commit a344e14

File tree

2 files changed

+56
-44
lines changed

2 files changed

+56
-44
lines changed

tools/destroy_database.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

tools/reset_database.py

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,75 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
"""
17+
Reset, purge and/or (re)create a Rucio test database.
18+
19+
Behavior
20+
------------------------+-----------------------+---------------------------+
21+
Flag(s) | What happens | Subsequent actions |
22+
------------------------+-----------------------+---------------------------+
23+
(no flag) | destroy_database() | build_database() + |
24+
| # drop_orm_tables | create_base_vo() + |
25+
| | create_root_account() |
26+
------------------------+-----------------------+---------------------------+
27+
-b / --purge-build | drop_everything() | build_database() + |
28+
| # purge_db | create_base_vo() + |
29+
| | create_root_account() |
30+
------------------------+-----------------------+---------------------------+
31+
-p / --purge | drop_everything() | nothing else.. |
32+
| # purge_db | the script ends |
33+
------------------------+-----------------------+---------------------------+
34+
"""
35+
1636
import os.path
1737
import sys
38+
from argparse import ArgumentParser
1839

40+
# Ensure package imports work when executed from any cwd
1941
base_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
2042
sys.path.append(base_path)
2143
os.chdir(base_path)
2244

23-
from argparse import ArgumentParser # noqa: E402
24-
25-
from rucio.db.sqla.util import build_database, create_base_vo, create_root_account, destroy_database, drop_everything # noqa: E402
45+
from rucio.db.sqla.util import ( # noqa: E402
46+
build_database, # noqa: E402
47+
create_base_vo, # noqa: E402
48+
create_root_account, # noqa: E402
49+
destroy_database, # noqa: E402
50+
drop_everything, # noqa: E402
51+
)
2652

2753
if __name__ == '__main__':
2854

29-
parser = ArgumentParser()
30-
parser.add_argument('-d', '--drop-everything', action="store_true", default=False, help='Drop all tables and constraints')
55+
parser = ArgumentParser(
56+
prog="reset_database.py",
57+
description="Reset the local Rucio database used in tests."
58+
)
59+
g = parser.add_mutually_exclusive_group()
60+
g.add_argument(
61+
"-b", "--purge-build",
62+
action="store_true",
63+
help="Purge EVERYTHING (tables, constraints, schema) "
64+
"and then rebuild a fresh schema with base VO + root account.",
65+
)
66+
g.add_argument(
67+
"-p", "--purge",
68+
action="store_true",
69+
help="Purge EVERYTHING and stop – do NOT recreate schema or accounts.",
70+
)
3171
args = parser.parse_args()
3272

33-
if args.drop_everything:
73+
# ------------------------------------------------------------------
74+
# 1. Decide how to reset
75+
# ------------------------------------------------------------------
76+
if args.purge_build or args.purge:
3477
drop_everything()
3578
else:
3679
destroy_database()
3780

38-
build_database()
39-
create_base_vo()
40-
create_root_account()
81+
# ------------------------------------------------------------------
82+
# 2. Decide what to rebuild
83+
# ------------------------------------------------------------------
84+
if not args.purge:
85+
build_database()
86+
create_base_vo()
87+
create_root_account()

0 commit comments

Comments
 (0)