Browse Source

Revert "added logs in migrate.py"

This reverts commit 8af5bc8033.
tags/9.6-1.1.0
Robin Thoni 7 years ago
parent
commit
701b263faa
2 changed files with 5 additions and 18 deletions
  1. 0
    2
      Dockerfile
  2. 5
    16
      migrate.py

+ 0
- 2
Dockerfile View File

29
 
29
 
30
 RUN rm -rf /var/log/*
30
 RUN rm -rf /var/log/*
31
 
31
 
32
-RUN touch /var/log/migrate.py.logs && chmod 777 /var/log/migrate.py.logs
33
-
34
 VOLUME "/var/lib/postgresql/backup"
32
 VOLUME "/var/lib/postgresql/backup"

+ 5
- 16
migrate.py View File

7
 import re
7
 import re
8
 import distutils.version
8
 import distutils.version
9
 import subprocess
9
 import subprocess
10
-import datetime
11
 
10
 
12
 
11
 
13
 def file_runner_pgsql(folder, file):
12
 def file_runner_pgsql(folder, file):
61
         if file.startswith('%s_' % (version)):
60
         if file.startswith('%s_' % (version)):
62
             run_file(folder, file, no_run, file_runners)
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
     files = list_files(folder)
64
     files = list_files(folder)
66
     versions = list_versions(files)
65
     versions = list_versions(files)
67
 
66
 
83
         print('Not running because --no-run was specified')
82
         print('Not running because --no-run was specified')
84
 
83
 
85
     if version_from is None:
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
     else:
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
     version_from_obj = distutils.version.StrictVersion('0.0.0' if version_from is None else version_from)
89
     version_from_obj = distutils.version.StrictVersion('0.0.0' if version_from is None else version_from)
100
     version_to_obj = distutils.version.StrictVersion(version_to)
90
     version_to_obj = distutils.version.StrictVersion(version_to)
120
     parser.add_argument('--no-run', dest='no_run', default=False, action='store_true', help='Do not run migration, just print')
110
     parser.add_argument('--no-run', dest='no_run', default=False, action='store_true', help='Do not run migration, just print')
121
     parser.add_argument('--version-from', dest='version_from', default=None, help='Current version, required if using --migrate, can not be used --init')
111
     parser.add_argument('--version-from', dest='version_from', default=None, help='Current version, required if using --migrate, can not be used --init')
122
     parser.add_argument('--version-to', dest='version_to', default=None, help='Final version, default to last available version is not given')
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
     args = parser.parse_args()
114
     args = parser.parse_args()
126
 
115
 
137
         if args.version_from is not None:
126
         if args.version_from is not None:
138
             print('--version-from can not be used with --init')
127
             print('--version-from can not be used with --init')
139
             return 64
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
     elif args.is_migrate:
130
     elif args.is_migrate:
142
         if args.version_from is None:
131
         if args.version_from is None:
143
             print('--version-from is required. Use --init to run all migrations')
132
             print('--version-from is required. Use --init to run all migrations')
144
             return 64
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
     else:
135
     else:
147
         print('Missing --init or --migrate')
136
         print('Missing --init or --migrate')
148
         return 64
137
         return 64

Loading…
Cancel
Save