|
@@ -7,7 +7,6 @@ import os.path
|
7
|
7
|
import re
|
8
|
8
|
import distutils.version
|
9
|
9
|
import subprocess
|
10
|
|
-import datetime
|
11
|
10
|
|
12
|
11
|
|
13
|
12
|
def file_runner_pgsql(folder, file):
|
|
@@ -61,7 +60,7 @@ def run_migration(folder, files, version, no_run, file_runners):
|
61
|
60
|
if file.startswith('%s_' % (version)):
|
62
|
61
|
run_file(folder, file, no_run, file_runners)
|
63
|
62
|
|
64
|
|
-def run_migrations(folder, version_from, version_to, no_run, file_runners, log_file):
|
|
63
|
+def run_migrations(folder, version_from, version_to, no_run, file_runners):
|
65
|
64
|
files = list_files(folder)
|
66
|
65
|
versions = list_versions(files)
|
67
|
66
|
|
|
@@ -83,18 +82,9 @@ def run_migrations(folder, version_from, version_to, no_run, file_runners, log_f
|
83
|
82
|
print('Not running because --no-run was specified')
|
84
|
83
|
|
85
|
84
|
if version_from is None:
|
86
|
|
- msg = 'Initialising from %s (inclusive) to %s (inclusive)' % (versions[0], version_to)
|
|
85
|
+ print('Initialising from %s (inclusive) to %s (inclusive)' % (versions[0], version_to))
|
87
|
86
|
else:
|
88
|
|
- msg = 'Migrating from %s (exclusive) to %s (inclusive)' % (version_from, version_to)
|
89
|
|
-
|
90
|
|
- print(msg)
|
91
|
|
-
|
92
|
|
- if not no_run:
|
93
|
|
- try:
|
94
|
|
- with open(log_file, "a") as f:
|
95
|
|
- f.write('%s: %s in %s\n' % (datetime.datetime.now(), msg, folder))
|
96
|
|
- except Exception as e:
|
97
|
|
- print('Failed to write logs in %: %s' % (log_file, e))
|
|
87
|
+ print('Migrating from %s (exclusive) to %s (inclusive)' % (version_from, version_to))
|
98
|
88
|
|
99
|
89
|
version_from_obj = distutils.version.StrictVersion('0.0.0' if version_from is None else version_from)
|
100
|
90
|
version_to_obj = distutils.version.StrictVersion(version_to)
|
|
@@ -120,7 +110,6 @@ def main():
|
120
|
110
|
parser.add_argument('--no-run', dest='no_run', default=False, action='store_true', help='Do not run migration, just print')
|
121
|
111
|
parser.add_argument('--version-from', dest='version_from', default=None, help='Current version, required if using --migrate, can not be used --init')
|
122
|
112
|
parser.add_argument('--version-to', dest='version_to', default=None, help='Final version, default to last available version is not given')
|
123
|
|
- parser.add_argument('--log-file', dest='log_file', default='/var/lib/postgresql/data/migrate.py.log', help='File to log migrations')
|
124
|
113
|
|
125
|
114
|
args = parser.parse_args()
|
126
|
115
|
|
|
@@ -137,12 +126,12 @@ def main():
|
137
|
126
|
if args.version_from is not None:
|
138
|
127
|
print('--version-from can not be used with --init')
|
139
|
128
|
return 64
|
140
|
|
- return run_migrations(args.folder, None, args.version_to, args.no_run, file_runners, args.log_file)
|
|
129
|
+ return run_migrations(args.folder, None, args.version_to, args.no_run, file_runners)
|
141
|
130
|
elif args.is_migrate:
|
142
|
131
|
if args.version_from is None:
|
143
|
132
|
print('--version-from is required. Use --init to run all migrations')
|
144
|
133
|
return 64
|
145
|
|
- return run_migrations(args.folder, args.version_from, args.version_to, args.no_run, file_runners, args.log_file)
|
|
134
|
+ return run_migrations(args.folder, args.version_from, args.version_to, args.no_run, file_runners)
|
146
|
135
|
else:
|
147
|
136
|
print('Missing --init or --migrate')
|
148
|
137
|
return 64
|