pgmini-migrate 0.1.2__tar.gz → 0.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pgmini-migrate
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: A minimal PostgreSQL migration tool for Python
5
5
  Author-email: Nguyen Vu Duy Luan <nvdluan@gmail.com>
6
6
  License: Copyright (c) 2025 Nguyen Vu Duy Luan
@@ -29,6 +29,7 @@ def load_env_file(env_path=".env"):
29
29
  # do not overwrite existing env set by host
30
30
  if k not in os.environ:
31
31
  os.environ[k] = v
32
+ print(f"Loaded env {k} from {env_path}: {v}")
32
33
 
33
34
 
34
35
  def build_conninfo_from_args(args):
@@ -154,9 +155,7 @@ def get_next_version_str(migrations_root):
154
155
  def create_migration(migrations_root, description):
155
156
  desc = description.strip()
156
157
  # sanitize description
157
- desc_clean = "_".join(
158
- c for c in desc.lower().replace(" ", "_") if (c.isalnum() or c == "_")
159
- )
158
+ desc_clean=desc.lower().replace(" ", "_").replace("-", "_")
160
159
  version = get_next_version_str(migrations_root)
161
160
  upgrade_name = f"{version}.{desc_clean}.upgrade.sql"
162
161
  downgrade_name = f"{version}.{desc_clean}.downgrade.sql"
@@ -269,11 +268,15 @@ def cmd_downgrade(args):
269
268
 
270
269
  def build_arg_parser():
271
270
  p = argparse.ArgumentParser(prog="pgmigrate", description="Simple PostgreSQL migration tool")
271
+
272
+ # NOTE: lấy default từ os.getenv() *tại thời điểm gọi*, không từ hằng module-level
273
+ migrations_default = os.getenv("MIGRATIONS_DIR", "migrations")
274
+
272
275
  p.add_argument("--env-file", default=".env", help="Path to .env file (default: .env)")
273
276
  p.add_argument(
274
277
  "--migrations",
275
- default=DEFAULT_MIGRATIONS_DIR,
276
- help=f"Root migrations dir (default: {DEFAULT_MIGRATIONS_DIR})",
278
+ default=migrations_default,
279
+ help=f"Root migrations dir (default: {migrations_default})",
277
280
  )
278
281
 
279
282
  # DB connection options (mutually override database_url)
@@ -303,16 +306,24 @@ def build_arg_parser():
303
306
 
304
307
  def main(argv=None):
305
308
  argv = argv if argv is not None else sys.argv[1:]
309
+
310
+ # -------------------------
311
+ # 1) pre-parse only --env-file
312
+ # -------------------------
313
+ pre_parser = argparse.ArgumentParser(add_help=False)
314
+ pre_parser.add_argument("--env-file", default=".env")
315
+ pre_args, _unknown = pre_parser.parse_known_args(argv)
316
+
317
+ # 2) load env file BEFORE building main parser so os.getenv picks values
318
+ if pre_args.env_file:
319
+ load_env_file(pre_args.env_file)
320
+
321
+ # 3) build the full parser (now os.getenv reflects .env content)
306
322
  parser = build_arg_parser()
307
- args = parser.parse_args(argv)
308
323
 
309
- # Load env file first (do not overwrite existing env vars)
310
- if args.env_file:
311
- load_env_file(args.env_file)
324
+ # 4) parse full args (using original argv)
325
+ args = parser.parse_args(argv)
312
326
 
313
- # prefer CLI args, else env
314
- # Re-populate db fields from env if not provided explicitly
315
- # (build_conninfo handles database_url precedence)
316
327
  # Dispatch commands:
317
328
  if args.cmd == "create":
318
329
  desc = " ".join(args.description)
@@ -320,8 +331,6 @@ def main(argv=None):
320
331
  return
321
332
 
322
333
  # For commands that touch DB, ensure connection info exists
323
- # Build conninfo now (will use args or environment)
324
- # If neither database_url nor db_name provided, abort
325
334
  conninfo = build_conninfo_from_args(args)
326
335
  if not conninfo:
327
336
  print("No database connection info provided. Provide --database-url or host/name/user/password or set env vars.")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pgmini-migrate
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: A minimal PostgreSQL migration tool for Python
5
5
  Author-email: Nguyen Vu Duy Luan <nvdluan@gmail.com>
6
6
  License: Copyright (c) 2025 Nguyen Vu Duy Luan
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pgmini-migrate"
7
- version = "0.1.2"
7
+ version = "0.1.3"
8
8
  description = "A minimal PostgreSQL migration tool for Python"
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="pgmini-migrate",
5
- version="0.1.2",
5
+ version="0.1.3",
6
6
  packages=find_packages(),
7
7
  install_requires=["psycopg2-binary", 'psycopg', 'python-dotenv'],
8
8
  entry_points={
File without changes
File without changes
File without changes