atquery 2.13.4__tar.gz → 2.14.0__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.
Files changed (68) hide show
  1. {atquery-2.13.4 → atquery-2.14.0}/PKG-INFO +1 -1
  2. {atquery-2.13.4 → atquery-2.14.0}/pyproject.toml +1 -1
  3. {atquery-2.13.4 → atquery-2.14.0}/pyproject.toml.orig +1 -1
  4. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/cli/columns.py +17 -8
  5. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/cli/ddl.py +18 -6
  6. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/cli/diff.py +3 -1
  7. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/cli/ecd.py +4 -2
  8. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/cli/main.py +59 -2
  9. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/cli/migrate.py +25 -13
  10. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/cli/routines.py +18 -6
  11. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/cli/scenario.py +3 -3
  12. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/cli/schemas.py +12 -2
  13. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/cli/tables.py +17 -8
  14. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/ecd/catalog.py +9 -0
  15. {atquery-2.13.4 → atquery-2.14.0}/LICENSE +0 -0
  16. {atquery-2.13.4 → atquery-2.14.0}/README.md +0 -0
  17. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/__init__.py +0 -0
  18. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/aio/__init__.py +0 -0
  19. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/aio/engine.py +0 -0
  20. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/aio/query.py +0 -0
  21. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/api_v2.py +0 -0
  22. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/atquery2.py +0 -0
  23. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/cli/__init__.py +0 -0
  24. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/dialect/__init__.py +0 -0
  25. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/dialect/duckdb.py +0 -0
  26. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/dialect/mysql/__init__.py +0 -0
  27. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/dialect/mysql/aio.py +0 -0
  28. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/dialect/mysql/core.py +0 -0
  29. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/dialect/mysql/dump/__init__.py +0 -0
  30. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/dialect/mysql/dump/__main__.py +0 -0
  31. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/dialect/mysql/dump/core.py +0 -0
  32. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/dialect/mysql/meta.py +0 -0
  33. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/dialect/mysql/pooling.py +0 -0
  34. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/dialect/mysql/restore/__init__.py +0 -0
  35. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/dialect/mysql/restore/__main__.py +0 -0
  36. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/dialect/mysql/restore/core.py +0 -0
  37. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/dialect/sqlite.py +0 -0
  38. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/diff/__init__.py +0 -0
  39. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/diff/comparator.py +0 -0
  40. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/diff/generator.py +0 -0
  41. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/diff/git_integration.py +0 -0
  42. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/diff/models.py +0 -0
  43. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/diff/parser.py +0 -0
  44. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/ecd/__init__.py +0 -0
  45. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/ecd/_toml.py +0 -0
  46. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/ecd/ddl.py +0 -0
  47. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/ecd/diff.py +0 -0
  48. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/ecd/erd.py +0 -0
  49. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/ecd/errors.py +0 -0
  50. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/ecd/model.py +0 -0
  51. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/ecd/parser.py +0 -0
  52. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/ecd/resolver.py +0 -0
  53. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/ecd/seed.py +0 -0
  54. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/ecd/skeleton.py +0 -0
  55. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/engine.py +0 -0
  56. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/factory.py +0 -0
  57. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/migration/__init__.py +0 -0
  58. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/migration/_migrator.py +0 -0
  59. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/migration/_protocol.py +0 -0
  60. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/migration/_standard.py +0 -0
  61. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/migration/_types.py +0 -0
  62. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/py.typed +0 -0
  63. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/testing/__init__.py +0 -0
  64. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/testing/creator.py +0 -0
  65. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/testing/loader.py +0 -0
  66. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/testing/schema.py +0 -0
  67. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/testing/validator.py +0 -0
  68. {atquery-2.13.4 → atquery-2.14.0}/src/atquery/type.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: atquery
3
- Version: 2.13.4
3
+ Version: 2.14.0
4
4
  Summary: A Python module for simplifying DBAPI usage with one-query-per-file SQL management.
5
5
  Keywords: sql,database,dbapi,mysql,sqlite,duckdb
6
6
  Author: alpine
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "atquery"
7
- version = "2.13.4"
7
+ version = "2.14.0"
8
8
  description = "A Python module for simplifying DBAPI usage with one-query-per-file SQL management."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "atquery"
7
- version = "2.13.4"
7
+ version = "2.14.0"
8
8
  description = "A Python module for simplifying DBAPI usage with one-query-per-file SQL management."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -9,6 +9,8 @@ from atquery.cli.main import (
9
9
  EXIT_SUCCESS,
10
10
  OutputWriter,
11
11
  add_output_format_arguments,
12
+ parse_qualified_name,
13
+ resolve_datasource_uri,
12
14
  )
13
15
  from atquery.dialect import create_datasource
14
16
 
@@ -55,8 +57,11 @@ Examples:
55
57
  # Pattern matching for tables
56
58
  atquery columns -d mysql://user:pass@localhost/mydb -n "user%"
57
59
 
58
- # Pattern matching for schemas
59
- atquery columns -d mysql://user:pass@localhost/ -s "mydb%" -n "user%"
60
+ # Pattern matching across schemas (schema.table notation)
61
+ atquery columns -d mysql://user:pass@localhost/ -n "tenant_%.user%"
62
+
63
+ # Override the connection schema for this command only
64
+ atquery columns -d mysql://user:pass@localhost/ -s mydb
60
65
 
61
66
  # Output as JSON
62
67
  atquery columns -d mysql://user:pass@localhost/mydb --json
@@ -66,17 +71,20 @@ Examples:
66
71
  "-d",
67
72
  "--datasource",
68
73
  required=False,
74
+ default=argparse.SUPPRESS,
69
75
  help="Database connection string (e.g., sqlite:///path/to/db.sqlite3, mysql://user:pass@host:port/db). Falls back to ATQUERY_DATASOURCE environment variable if not specified.",
70
76
  )
71
77
 
72
78
  parser.add_argument(
73
79
  "-s",
74
80
  "--schema",
75
- help="Schema name or pattern (%%, _ wildcards supported). If not specified, uses default schema.",
81
+ required=False,
82
+ default=argparse.SUPPRESS,
83
+ help="Override the schema/database segment of the resolved connection URI (applies to this command only)",
76
84
  )
77
85
 
78
86
  parser.add_argument(
79
- "-n", "--name", help="Table name or pattern (%%, _ wildcards supported). If not specified, returns all tables."
87
+ "-n", "--name", help="Table name or pattern (%%, _ wildcards supported). Use 'schema.table' notation (e.g. 'tenant_%%.orders') to also filter by schema. If not specified, returns all tables in the connected schema."
80
88
  )
81
89
 
82
90
  add_output_format_arguments(parser)
@@ -92,8 +100,8 @@ def execute_columns(args: argparse.Namespace) -> int:
92
100
  int: 終了コード
93
101
  """
94
102
 
95
- # データベース接続文字列の取得(優先順位: 引数 > 環境変数)
96
- database_uri = args.datasource or os.environ.get("ATQUERY_DATASOURCE")
103
+ # データベース接続文字列の取得(優先順位: 引数 > 環境変数)、-sがあればschema部分を上書き
104
+ database_uri = resolve_datasource_uri(getattr(args, "datasource", None), getattr(args, "schema", None))
97
105
 
98
106
  if not database_uri:
99
107
  print(
@@ -106,9 +114,10 @@ def execute_columns(args: argparse.Namespace) -> int:
106
114
  # データソースの作成
107
115
  datasource = create_datasource(database_uri)
108
116
 
109
- # 構造情報の取得
117
+ # 構造情報の取得(-nは 'schema.table' 形式ならschema/tableに分割)
110
118
  with datasource.connect() as conn:
111
- result = conn.meta.columns(schema=args.schema, table=args.name)
119
+ schema_filter, name_filter = parse_qualified_name(args.name)
120
+ result = conn.meta.columns(schema=schema_filter, table=name_filter)
112
121
 
113
122
  # 出力処理
114
123
  json_indent = None if args.compact else 2
@@ -9,6 +9,8 @@ from atquery.cli.main import (
9
9
  EXIT_SUCCESS,
10
10
  OutputWriter,
11
11
  add_output_format_arguments,
12
+ parse_qualified_name,
13
+ resolve_datasource_uri,
12
14
  )
13
15
  from atquery.dialect import create_datasource
14
16
 
@@ -50,6 +52,12 @@ Examples:
50
52
  # Get DDL for routines (procedures/functions)
51
53
  atquery ddl -d mysql://user:pass@localhost/mydb -n "my_proc%"
52
54
 
55
+ # Pattern matching across schemas (schema.object notation)
56
+ atquery ddl -d mysql://user:pass@localhost/ -n "tenant_%.user%"
57
+
58
+ # Override the connection schema for this command only
59
+ atquery ddl -d mysql://user:pass@localhost/ -s mydb -n users
60
+
53
61
  # Output as JSON
54
62
  atquery ddl -d mysql://user:pass@localhost/mydb -n users --json
55
63
  """
@@ -58,17 +66,20 @@ Examples:
58
66
  "-d",
59
67
  "--datasource",
60
68
  required=False,
69
+ default=argparse.SUPPRESS,
61
70
  help="Database connection string (e.g., sqlite:///path/to/db.sqlite3, mysql://user:pass@host:port/db). Falls back to ATQUERY_DATASOURCE environment variable if not specified.",
62
71
  )
63
72
 
64
73
  parser.add_argument(
65
74
  "-s",
66
75
  "--schema",
67
- help="Schema name or pattern (%%, _ wildcards supported). If not specified, uses default schema.",
76
+ required=False,
77
+ default=argparse.SUPPRESS,
78
+ help="Override the schema/database segment of the resolved connection URI (applies to this command only)",
68
79
  )
69
80
 
70
81
  parser.add_argument(
71
- "-n", "--name", help="Object name or pattern (%%, _ wildcards supported). If not specified, returns all objects (tables, views, routines)."
82
+ "-n", "--name", help="Object name or pattern (%%, _ wildcards supported). Use 'schema.object' notation (e.g. 'tenant_%%.orders') to also filter by schema. If not specified, returns all objects (tables, views, routines) in the connected schema."
72
83
  )
73
84
 
74
85
  add_output_format_arguments(parser)
@@ -84,8 +95,8 @@ def execute_ddl(args: argparse.Namespace) -> int:
84
95
  int: 終了コード
85
96
  """
86
97
 
87
- # データベース接続文字列の取得(優先順位: 引数 > 環境変数)
88
- database_uri = args.datasource or os.environ.get("ATQUERY_DATASOURCE")
98
+ # データベース接続文字列の取得(優先順位: 引数 > 環境変数)、-sがあればschema部分を上書き
99
+ database_uri = resolve_datasource_uri(getattr(args, "datasource", None), getattr(args, "schema", None))
89
100
 
90
101
  if not database_uri:
91
102
  print(
@@ -98,9 +109,10 @@ def execute_ddl(args: argparse.Namespace) -> int:
98
109
  # データソースの作成
99
110
  datasource = create_datasource(database_uri)
100
111
 
101
- # CREATE文の取得
112
+ # CREATE文の取得(-nは 'schema.object' 形式ならschema/objectに分割)
102
113
  with datasource.connect() as conn:
103
- result = conn.meta.ddl(schema=args.schema, name=args.name)
114
+ schema_filter, name_filter = parse_qualified_name(args.name)
115
+ result = conn.meta.ddl(schema=schema_filter, name=name_filter)
104
116
 
105
117
  # 出力処理
106
118
  json_indent = None if args.compact else 2
@@ -71,6 +71,7 @@ Note:
71
71
  type=str,
72
72
  nargs="?",
73
73
  const="",
74
+ default=argparse.SUPPRESS,
74
75
  metavar="URI",
75
76
  help=(
76
77
  "データソースモード: 実DBの現在のスキーマを比較元として使用する。"
@@ -82,7 +83,8 @@ Note:
82
83
  "--schema",
83
84
  type=str,
84
85
  metavar="SCHEMA",
85
- help="データソースモード: DB側の比較対象スキーマ名",
86
+ default=argparse.SUPPRESS,
87
+ help="データソースモード: DB側の比較対象スキーマ名(ルートの -s/--schema と共通、省略時は継承される)",
86
88
  )
87
89
  parser.add_argument(
88
90
  "-o", "--output",
@@ -52,7 +52,7 @@ def setup_parser(parser: argparse.ArgumentParser) -> None:
52
52
  help="Generate an ECD skeleton from an existing database schema",
53
53
  )
54
54
  _add_datasource_arg(skeleton_parser)
55
- skeleton_parser.add_argument("-s", "--schema", help="Schema name")
55
+ skeleton_parser.add_argument("-s", "--schema", default=argparse.SUPPRESS, help="Schema name(ルートの -s/--schema と共通、省略時は継承される)")
56
56
  skeleton_parser.add_argument("-n", "--name", help="Table/view name or pattern (%%, _ wildcards supported)")
57
57
  skeleton_parser.add_argument("-o", "--output", help="出力先ファイル(省略時は標準出力)")
58
58
 
@@ -120,7 +120,7 @@ def setup_parser(parser: argparse.ArgumentParser) -> None:
120
120
  )
121
121
  _add_ecd_source_args(diff_parser)
122
122
  _add_datasource_arg(diff_parser)
123
- diff_parser.add_argument("-s", "--schema", help="Schema name(DB側の比較対象スキーマ)")
123
+ diff_parser.add_argument("-s", "--schema", default=argparse.SUPPRESS, help="Schema name(DB側の比較対象スキーマ。ルートの -s/--schema と共通、省略時は継承される)")
124
124
  diff_parser.add_argument(
125
125
  "--rename",
126
126
  action="append",
@@ -141,6 +141,7 @@ def _add_datasource_arg(parser: argparse.ArgumentParser) -> None:
141
141
  "-d",
142
142
  "--datasource",
143
143
  required=False,
144
+ default=argparse.SUPPRESS,
144
145
  help="Database connection string. Falls back to ATQUERY_DATASOURCE environment variable if not specified.",
145
146
  )
146
147
 
@@ -346,6 +347,7 @@ def _execute_catalog(args: argparse.Namespace) -> int:
346
347
  no_diagram=args.no_diagram,
347
348
  diagram_theme=args.diagram_theme,
348
349
  all_source_files=[doc.path for doc in documents],
350
+ schema_by_file={doc.path: doc.frontmatter.schema for doc in documents},
349
351
  )
350
352
  except ECDError as e:
351
353
  print(f"Error: {e}", file=sys.stderr)
@@ -9,6 +9,7 @@ import sys
9
9
  from io import StringIO
10
10
  from pathlib import Path
11
11
  from typing import Any, Optional, Sequence, cast
12
+ from urllib.parse import urlparse, urlunparse
12
13
 
13
14
  from atquery.atquery2 import ATQuery
14
15
  from atquery.dialect import create_datasource
@@ -27,6 +28,51 @@ EXIT_ERROR = 1
27
28
  EXIT_INTERRUPTED = 130 # 128 + SIGINT(2)
28
29
 
29
30
 
31
+ def resolve_datasource_uri(
32
+ datasource_arg: Optional[str],
33
+ schema_override: Optional[str],
34
+ env_var: str = "ATQUERY_DATASOURCE",
35
+ ) -> Optional[str]:
36
+ """-d/環境変数からURIを解決し、-s指定があればschema(database)部分だけ差し替える
37
+
38
+ ADR-0039: -s/--schema はCLI全体で「接続URIのschema/database部分の上書き」を意味する。
39
+ クエリパラメータ・ポート・認証情報は保ったまま、path部分だけを置き換える。
40
+
41
+ Args:
42
+ datasource_arg: -d/--datasource で渡された値(未指定ならNone)
43
+ schema_override: -s/--schema で渡された値(未指定ならNone)
44
+ env_var: フォールバック先の環境変数名
45
+
46
+ Returns:
47
+ str | None: 解決済みのURI(datasource_arg・環境変数のいずれも無ければNone)
48
+ """
49
+ uri = datasource_arg or os.environ.get(env_var)
50
+ if uri and schema_override:
51
+ parsed = urlparse(uri)
52
+ uri = urlunparse(parsed._replace(path="/" + schema_override))
53
+ return uri
54
+
55
+
56
+ def parse_qualified_name(name: Optional[str]) -> tuple[Optional[str], Optional[str]]:
57
+ """-n/--name の値を 'schema.table' 形式ならschemaとtableに分割する(ADR-0039)
58
+
59
+ 最初の '.' で分割する。ドットが含まれない場合はschema側をNoneとし、
60
+ 値全体をtable側のパターンとして扱う(従来通り、接続中のデフォルトスキーマが対象)。
61
+
62
+ Args:
63
+ name: -n/--name で渡された値
64
+
65
+ Returns:
66
+ tuple[str | None, str | None]: (schemaパターン, table/routine/objectパターン)
67
+ """
68
+ if name is None:
69
+ return None, None
70
+ if "." in name:
71
+ schema, _, rest = name.partition(".")
72
+ return schema, rest
73
+ return None, name
74
+
75
+
30
76
  def get_version() -> str:
31
77
  """パッケージのバージョンを取得
32
78
 
@@ -535,6 +581,10 @@ Examples:
535
581
  atquery -f query.sql
536
582
  echo "SELECT * FROM users" | atquery
537
583
 
584
+ # Override only the schema/database segment of ATQUERY_DATASOURCE for this run
585
+ atquery -s another_db -f query.sql
586
+ atquery -s another_db tables
587
+
538
588
  # Pass parameters
539
589
  atquery -f query.sql -p name=John -p age=30
540
590
 
@@ -640,6 +690,13 @@ Examples:
640
690
  help="Database connection string (or set ATQUERY_DATASOURCE env var)",
641
691
  )
642
692
 
693
+ parser.add_argument(
694
+ "-s",
695
+ "--schema",
696
+ required=False,
697
+ help="Override the schema/database segment of the resolved connection URI (applies to the root command and all subcommands)",
698
+ )
699
+
643
700
  sql_source_group = parser.add_mutually_exclusive_group()
644
701
  sql_source_group.add_argument(
645
702
  "-f", "--file", required=False, help="SQL file path (use '-' or omit for stdin)"
@@ -745,8 +802,8 @@ Examples:
745
802
  from atquery.cli.ecd import execute_ecd
746
803
  return execute_ecd(args)
747
804
 
748
- # データベース接続文字列の取得(優先順位: 引数 > 環境変数)
749
- database_uri = args.datasource or os.environ.get("ATQUERY_DATASOURCE")
805
+ # データベース接続文字列の取得(優先順位: 引数 > 環境変数)、-s/--schemaがあればschema部分を上書き
806
+ database_uri = resolve_datasource_uri(args.datasource, args.schema)
750
807
 
751
808
  # --print-query でない場合は database_uri が必須
752
809
  if not args.print_query and not database_uri:
@@ -5,7 +5,7 @@ import os
5
5
  import sys
6
6
  from typing import Any
7
7
 
8
- from atquery.cli.main import EXIT_ERROR, EXIT_SUCCESS
8
+ from atquery.cli.main import EXIT_ERROR, EXIT_SUCCESS, resolve_datasource_uri
9
9
  from atquery.dialect import create_datasource
10
10
 
11
11
 
@@ -45,19 +45,19 @@ def _resolve_migration(args: argparse.Namespace) -> Any | None:
45
45
  return cls()
46
46
 
47
47
  if args.dir:
48
- database_uri = args.datasource or os.environ.get("ATQUERY_DATASOURCE", "")
49
- if database_uri.startswith("mysql"):
48
+ database_uri = resolve_datasource_uri(getattr(args, "datasource", None), getattr(args, "schema", None))
49
+ if database_uri and database_uri.startswith("mysql"):
50
50
  return StandardMySQLMigration(
51
51
  migrations_dir=args.dir,
52
52
  name=args.name,
53
- table_prefix=args.table_prefix,
53
+ table_prefix=args.migration_table_prefix,
54
54
  baseline_revision=args.baseline_revision,
55
- schema=args.schema,
55
+ schema=args.migration_schema,
56
56
  )
57
57
  return StandardMigration(
58
58
  migrations_dir=args.dir,
59
59
  name=args.name,
60
- table_prefix=args.table_prefix,
60
+ table_prefix=args.migration_table_prefix,
61
61
  baseline_revision=args.baseline_revision,
62
62
  )
63
63
 
@@ -74,9 +74,15 @@ def _add_common_args(parser: argparse.ArgumentParser) -> None:
74
74
  parser.add_argument(
75
75
  "-d",
76
76
  "--datasource",
77
- default=os.environ.get("ATQUERY_DATASOURCE"),
77
+ default=argparse.SUPPRESS,
78
78
  help="Database connection string (env: ATQUERY_DATASOURCE)",
79
79
  )
80
+ parser.add_argument(
81
+ "-s",
82
+ "--schema",
83
+ default=argparse.SUPPRESS,
84
+ help="Override the schema/database segment of the resolved connection URI (applies to this command only)",
85
+ )
80
86
  parser.add_argument(
81
87
  "--dir",
82
88
  default=os.environ.get("ATQUERY_MIGRATION_DIR"),
@@ -95,9 +101,9 @@ def _add_common_args(parser: argparse.ArgumentParser) -> None:
95
101
  help="Migration name key in the management table (env: ATQUERY_MIGRATION_NAME, default: default)",
96
102
  )
97
103
  parser.add_argument(
98
- "--table-prefix",
104
+ "--migration-table-prefix",
99
105
  default=os.environ.get("ATQUERY_MIGRATION_TABLE_PREFIX", "atquery"),
100
- dest="table_prefix",
106
+ dest="migration_table_prefix",
101
107
  help="Prefix for management table names (env: ATQUERY_MIGRATION_TABLE_PREFIX, default: atquery)",
102
108
  )
103
109
  parser.add_argument(
@@ -109,8 +115,9 @@ def _add_common_args(parser: argparse.ArgumentParser) -> None:
109
115
  help="Initial revision when no record exists; scripts up to N are skipped (env: ATQUERY_MIGRATION_BASELINE_REVISION, default: 0)",
110
116
  )
111
117
  parser.add_argument(
112
- "--schema",
118
+ "--migration-schema",
113
119
  default=os.environ.get("ATQUERY_MIGRATION_SCHEMA"),
120
+ dest="migration_schema",
114
121
  metavar="SCHEMA",
115
122
  help="Schema for management tables, MySQL only (env: ATQUERY_MIGRATION_SCHEMA)",
116
123
  )
@@ -142,11 +149,14 @@ Examples:
142
149
  atquery migrate run --dir ddl/migrate --refresh-routines
143
150
 
144
151
  # Multi-schema: isolate management tables per schema
145
- atquery migrate run --dir ddl/app --name app --schema infra
146
- atquery migrate run --dir ddl/log --name log --schema infra
152
+ atquery migrate run --dir ddl/app --name app --migration-schema infra
153
+ atquery migrate run --dir ddl/log --name log --migration-schema infra
147
154
 
148
155
  # Change management table prefix
149
- atquery migrate run --dir ddl/migrate --table-prefix _mig
156
+ atquery migrate run --dir ddl/migrate --migration-table-prefix _mig
157
+
158
+ # Apply migrations against a different schema than ATQUERY_DATASOURCE points to
159
+ atquery migrate run --dir ddl/migrate -s another_db
150
160
 
151
161
  # First-time adoption on existing DB (skip scripts up to revision 15)
152
162
  atquery migrate run --dir ddl/migrate --baseline-revision 15
@@ -202,6 +212,7 @@ def execute_migrate(args: argparse.Namespace) -> int:
202
212
 
203
213
 
204
214
  def _execute_status(args: argparse.Namespace) -> int:
215
+ args.datasource = resolve_datasource_uri(getattr(args, "datasource", None), getattr(args, "schema", None))
205
216
  if not args.datasource:
206
217
  print(
207
218
  "Error: -d/--datasource または ATQUERY_DATASOURCE 環境変数を指定してください",
@@ -239,6 +250,7 @@ def _execute_status(args: argparse.Namespace) -> int:
239
250
 
240
251
 
241
252
  def _execute_run(args: argparse.Namespace) -> int:
253
+ args.datasource = resolve_datasource_uri(getattr(args, "datasource", None), getattr(args, "schema", None))
242
254
  if not args.datasource:
243
255
  print(
244
256
  "Error: -d/--datasource または ATQUERY_DATASOURCE 環境変数を指定してください",
@@ -9,6 +9,8 @@ from atquery.cli.main import (
9
9
  EXIT_SUCCESS,
10
10
  OutputWriter,
11
11
  add_output_format_arguments,
12
+ parse_qualified_name,
13
+ resolve_datasource_uri,
12
14
  )
13
15
  from atquery.dialect import create_datasource
14
16
 
@@ -41,6 +43,12 @@ Examples:
41
43
  # Pattern matching for routines
42
44
  atquery routines -d mysql://user:pass@localhost/mydb -n "calc_%"
43
45
 
46
+ # Pattern matching across schemas (schema.routine notation)
47
+ atquery routines -d mysql://user:pass@localhost/ -n "tenant_%.calc_%"
48
+
49
+ # Override the connection schema for this command only
50
+ atquery routines -d mysql://user:pass@localhost/ -s mydb
51
+
44
52
  # Output as JSON
45
53
  atquery routines -d mysql://user:pass@localhost/mydb --json
46
54
  """
@@ -49,17 +57,20 @@ Examples:
49
57
  "-d",
50
58
  "--datasource",
51
59
  required=False,
60
+ default=argparse.SUPPRESS,
52
61
  help="Database connection string (e.g., mysql://user:pass@host:port/db). Falls back to ATQUERY_DATASOURCE environment variable if not specified.",
53
62
  )
54
63
 
55
64
  parser.add_argument(
56
65
  "-s",
57
66
  "--schema",
58
- help="Schema name or pattern (%%, _ wildcards supported). If not specified, uses default schema.",
67
+ required=False,
68
+ default=argparse.SUPPRESS,
69
+ help="Override the schema/database segment of the resolved connection URI (applies to this command only)",
59
70
  )
60
71
 
61
72
  parser.add_argument(
62
- "-n", "--name", help="Routine name or pattern (%%, _ wildcards supported). If not specified, returns all routines."
73
+ "-n", "--name", help="Routine name or pattern (%%, _ wildcards supported). Use 'schema.routine' notation (e.g. 'tenant_%%.calc_%%') to also filter by schema. If not specified, returns all routines in the connected schema."
63
74
  )
64
75
 
65
76
  add_output_format_arguments(parser)
@@ -75,8 +86,8 @@ def execute_routines(args: argparse.Namespace) -> int:
75
86
  int: 終了コード
76
87
  """
77
88
 
78
- # データベース接続文字列の取得(優先順位: 引数 > 環境変数)
79
- database_uri = args.datasource or os.environ.get("ATQUERY_DATASOURCE")
89
+ # データベース接続文字列の取得(優先順位: 引数 > 環境変数)、-sがあればschema部分を上書き
90
+ database_uri = resolve_datasource_uri(getattr(args, "datasource", None), getattr(args, "schema", None))
80
91
 
81
92
  if not database_uri:
82
93
  print(
@@ -89,9 +100,10 @@ def execute_routines(args: argparse.Namespace) -> int:
89
100
  # データソースの作成
90
101
  datasource = create_datasource(database_uri)
91
102
 
92
- # ルーチン構造の取得
103
+ # ルーチン構造の取得(-nは 'schema.routine' 形式ならschema/routineに分割)
93
104
  with datasource.connect() as conn:
94
- result = conn.meta.routines(schema=args.schema, routine=args.name)
105
+ schema_filter, name_filter = parse_qualified_name(args.name)
106
+ result = conn.meta.routines(schema=schema_filter, routine=name_filter)
95
107
 
96
108
  # 出力処理
97
109
  json_indent = None if args.compact else 2
@@ -27,6 +27,8 @@ import argparse
27
27
  import sys
28
28
  from pathlib import Path
29
29
 
30
+ from atquery.cli.main import resolve_datasource_uri
31
+
30
32
 
31
33
  def setup_parser(parser: argparse.ArgumentParser) -> None:
32
34
  """scenario サブコマンドのパーサー設定"""
@@ -97,9 +99,7 @@ def execute_scenario(args) -> int:
97
99
 
98
100
  import atquery
99
101
 
100
- database_uri = getattr(args, "datasource", None)
101
- import os
102
- database_uri = database_uri or os.environ.get("ATQUERY_DATASOURCE")
102
+ database_uri = resolve_datasource_uri(getattr(args, "datasource", None), getattr(args, "schema", None))
103
103
 
104
104
  if not database_uri:
105
105
  print(
@@ -9,6 +9,7 @@ from atquery.cli.main import (
9
9
  EXIT_SUCCESS,
10
10
  OutputWriter,
11
11
  add_output_format_arguments,
12
+ resolve_datasource_uri,
12
13
  )
13
14
  from atquery.dialect import create_datasource
14
15
 
@@ -49,9 +50,18 @@ Examples:
49
50
  "-d",
50
51
  "--datasource",
51
52
  required=False,
53
+ default=argparse.SUPPRESS,
52
54
  help="Database connection string (e.g., sqlite:///path/to/db.sqlite3, mysql://user:pass@host:port/db). Falls back to ATQUERY_DATASOURCE environment variable if not specified.",
53
55
  )
54
56
 
57
+ parser.add_argument(
58
+ "-s",
59
+ "--schema",
60
+ required=False,
61
+ default=argparse.SUPPRESS,
62
+ help="Override the schema/database segment of the resolved connection URI (applies to this command only)",
63
+ )
64
+
55
65
  parser.add_argument(
56
66
  "-n",
57
67
  "--name",
@@ -71,8 +81,8 @@ def execute_schemas(args: argparse.Namespace) -> int:
71
81
  int: 終了コード
72
82
  """
73
83
 
74
- # データベース接続文字列の取得(優先順位: 引数 > 環境変数)
75
- database_uri = args.datasource or os.environ.get("ATQUERY_DATASOURCE")
84
+ # データベース接続文字列の取得(優先順位: 引数 > 環境変数)、-sがあればschema部分を上書き
85
+ database_uri = resolve_datasource_uri(getattr(args, "datasource", None), getattr(args, "schema", None))
76
86
 
77
87
  if not database_uri:
78
88
  print(
@@ -9,6 +9,8 @@ from atquery.cli.main import (
9
9
  EXIT_SUCCESS,
10
10
  OutputWriter,
11
11
  add_output_format_arguments,
12
+ parse_qualified_name,
13
+ resolve_datasource_uri,
12
14
  )
13
15
  from atquery.dialect import create_datasource
14
16
 
@@ -61,8 +63,11 @@ Examples:
61
63
  # Pattern matching for tables
62
64
  atquery tables -d mysql://user:pass@localhost/mydb -n "user%"
63
65
 
64
- # Pattern matching for schemas
65
- atquery tables -d mysql://user:pass@localhost/ -s "mydb%" -n "user%"
66
+ # Pattern matching across schemas (schema.table notation)
67
+ atquery tables -d mysql://user:pass@localhost/ -n "tenant_%.user%"
68
+
69
+ # Override the connection schema for this command only
70
+ atquery tables -d mysql://user:pass@localhost/ -s mydb
66
71
 
67
72
  # Output as JSON
68
73
  atquery tables -d mysql://user:pass@localhost/mydb --json
@@ -72,17 +77,20 @@ Examples:
72
77
  "-d",
73
78
  "--datasource",
74
79
  required=False,
80
+ default=argparse.SUPPRESS,
75
81
  help="Database connection string (e.g., sqlite:///path/to/db.sqlite3, mysql://user:pass@host:port/db). Falls back to ATQUERY_DATASOURCE environment variable if not specified.",
76
82
  )
77
83
 
78
84
  parser.add_argument(
79
85
  "-s",
80
86
  "--schema",
81
- help="Schema name or pattern (%%, _ wildcards supported). If not specified, uses default schema.",
87
+ required=False,
88
+ default=argparse.SUPPRESS,
89
+ help="Override the schema/database segment of the resolved connection URI (applies to this command only)",
82
90
  )
83
91
 
84
92
  parser.add_argument(
85
- "-n", "--name", help="Table/view name or pattern (%%, _ wildcards supported). If not specified, returns all tables and views."
93
+ "-n", "--name", help="Table/view name or pattern (%%, _ wildcards supported). Use 'schema.table' notation (e.g. 'tenant_%%.orders') to also filter by schema. If not specified, returns all tables and views in the connected schema."
86
94
  )
87
95
 
88
96
  add_output_format_arguments(parser)
@@ -98,8 +106,8 @@ def execute_tables(args: argparse.Namespace) -> int:
98
106
  int: 終了コード
99
107
  """
100
108
 
101
- # データベース接続文字列の取得(優先順位: 引数 > 環境変数)
102
- database_uri = args.datasource or os.environ.get("ATQUERY_DATASOURCE")
109
+ # データベース接続文字列の取得(優先順位: 引数 > 環境変数)、-sがあればschema部分を上書き
110
+ database_uri = resolve_datasource_uri(getattr(args, "datasource", None), getattr(args, "schema", None))
103
111
 
104
112
  if not database_uri:
105
113
  print(
@@ -112,9 +120,10 @@ def execute_tables(args: argparse.Namespace) -> int:
112
120
  # データソースの作成
113
121
  datasource = create_datasource(database_uri)
114
122
 
115
- # テーブル一覧の取得
123
+ # テーブル一覧の取得(-nは 'schema.table' 形式ならschema/tableに分割)
116
124
  with datasource.connect() as conn:
117
- result = conn.meta.tables(schema=args.schema, table=args.name)
125
+ schema_filter, name_filter = parse_qualified_name(args.name)
126
+ result = conn.meta.tables(schema=schema_filter, table=name_filter)
118
127
 
119
128
  # 出力処理
120
129
  json_indent = None if args.compact else 2
@@ -28,6 +28,8 @@
28
28
  - `ecd = "columns"`のみで構成されるファイル(columns glossary、テーブル/VIEWを持たない)も
29
29
  `all_source_files`経由でファイル参照リンク・`## Summary`・`## [label]`見出しに登場させる
30
30
  (中身はソースファイルへのリンクのみで、Mermaid図・見出しリンク一覧・詳細セクションは出さない)
31
+ - frontmatterの`schema`は`schema_by_file`経由で受け取り、`## [label]`見出し直下に
32
+ `* **Schema:** <schema>`として出力する(未指定のファイルは出力しない)
31
33
  """
32
34
 
33
35
  import os
@@ -55,6 +57,7 @@ def generate_catalog_markdown(
55
57
  no_diagram: bool = False,
56
58
  diagram_theme: str | None = None,
57
59
  all_source_files: Sequence[str] = (),
60
+ schema_by_file: dict[str, str | None] | None = None,
58
61
  ) -> str:
59
62
  """Markdownカタログ文字列を生成する。
60
63
 
@@ -65,7 +68,10 @@ def generate_catalog_markdown(
65
68
  `all_source_files`は読み込んだ全ECDファイルのパス(読み込み順)。`ecd = "columns"`のみで
66
69
  テーブル/VIEWを持たないファイル(columns glossary)も、ソースファイルへのリンクのみのセクション
67
70
  として登場させるために使う(テーブル/VIEWを持つファイルのみを渡した場合と結果は変わらない)。
71
+ `schema_by_file`はECDファイルパス->frontmatterの`schema`。`## [label]`見出し直下に
72
+ `* **Schema:**`として表示するために使う(省略時・値がNoneのファイルは表示しない)。
68
73
  """
74
+ schema_by_file = schema_by_file or {}
69
75
  base_dir = os.path.dirname(os.path.abspath(output_path)) if output_path else os.getcwd()
70
76
 
71
77
  source_files: list[str] = []
@@ -103,6 +109,9 @@ def generate_catalog_markdown(
103
109
  lines.append("")
104
110
  lines.append(f"## [{labels[source_file]}](#{_slugify(labels[source_file])})")
105
111
  lines.append(f"[Source File↗][{labels[source_file]}]")
112
+ file_schema = schema_by_file.get(source_file)
113
+ if file_schema:
114
+ lines.append(f"* **Schema:** {file_schema}")
106
115
 
107
116
  if not no_diagram:
108
117
  diagram_lines = _mermaid_diagram_lines(file_tables, tables_by_name, theme=diagram_theme)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes