Coverage for watcher/db/migration.py: 45%

20 statements  

« prev     ^ index     » next       coverage.py v7.8.2, created at 2025-06-17 12:22 +0000

1# Copyright 2010 United States Government as represented by the 

2# Administrator of the National Aeronautics and Space Administration. 

3# All Rights Reserved. 

4# 

5# Licensed under the Apache License, Version 2.0 (the "License"); you may 

6# not use this file except in compliance with the License. You may obtain 

7# a copy of the License at 

8# 

9# http://www.apache.org/licenses/LICENSE-2.0 

10# 

11# Unless required by applicable law or agreed to in writing, software 

12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 

13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 

14# License for the specific language governing permissions and limitations 

15# under the License. 

16 

17"""Database setup and migration commands.""" 

18 

19from oslo_config import cfg 

20from stevedore import driver 

21 

22_IMPL = None 

23 

24 

25def get_backend(): 

26 global _IMPL 

27 if not _IMPL: 

28 cfg.CONF.import_opt('backend', 'oslo_db.options', group='database') 

29 _IMPL = driver.DriverManager("watcher.database.migration_backend", 

30 cfg.CONF.database.backend).driver 

31 return _IMPL 

32 

33 

34def upgrade(version=None): 

35 """Migrate the database to `version` or the most recent version.""" 

36 return get_backend().upgrade(version) 

37 

38 

39def downgrade(version=None): 

40 return get_backend().downgrade(version) 

41 

42 

43def version(): 

44 return get_backend().version() 

45 

46 

47def stamp(version): 

48 return get_backend().stamp(version) 

49 

50 

51def revision(message, autogenerate): 

52 return get_backend().revision(message, autogenerate) 

53 

54 

55def create_schema(): 

56 return get_backend().create_schema()