pum 1.1.17__tar.gz → 1.2.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 (35) hide show
  1. {pum-1.1.17 → pum-1.2.0}/PKG-INFO +1 -1
  2. {pum-1.1.17 → pum-1.2.0}/pum/config_model.py +13 -2
  3. {pum-1.1.17 → pum-1.2.0}/pum/pum_config.py +5 -2
  4. {pum-1.1.17 → pum-1.2.0}/pum/role_manager.py +11 -6
  5. {pum-1.1.17 → pum-1.2.0}/pum/schema_migrations.py +2 -2
  6. {pum-1.1.17 → pum-1.2.0}/pum/upgrader.py +8 -7
  7. {pum-1.1.17 → pum-1.2.0}/pum.egg-info/PKG-INFO +1 -1
  8. {pum-1.1.17 → pum-1.2.0}/pyproject.toml +1 -1
  9. {pum-1.1.17 → pum-1.2.0}/test/test_config.py +5 -0
  10. {pum-1.1.17 → pum-1.2.0}/test/test_roles.py +14 -0
  11. {pum-1.1.17 → pum-1.2.0}/test/test_upgrader.py +18 -0
  12. {pum-1.1.17 → pum-1.2.0}/LICENSE +0 -0
  13. {pum-1.1.17 → pum-1.2.0}/README.md +0 -0
  14. {pum-1.1.17 → pum-1.2.0}/pum/__init__.py +0 -0
  15. {pum-1.1.17 → pum-1.2.0}/pum/changelog.py +0 -0
  16. {pum-1.1.17 → pum-1.2.0}/pum/checker.py +0 -0
  17. {pum-1.1.17 → pum-1.2.0}/pum/cli.py +0 -0
  18. {pum-1.1.17 → pum-1.2.0}/pum/dependency_handler.py +0 -0
  19. {pum-1.1.17 → pum-1.2.0}/pum/dumper.py +0 -0
  20. {pum-1.1.17 → pum-1.2.0}/pum/exceptions.py +0 -0
  21. {pum-1.1.17 → pum-1.2.0}/pum/hook.py +0 -0
  22. {pum-1.1.17 → pum-1.2.0}/pum/info.py +0 -0
  23. {pum-1.1.17 → pum-1.2.0}/pum/parameter.py +0 -0
  24. {pum-1.1.17 → pum-1.2.0}/pum/sql_content.py +0 -0
  25. {pum-1.1.17 → pum-1.2.0}/pum.egg-info/SOURCES.txt +0 -0
  26. {pum-1.1.17 → pum-1.2.0}/pum.egg-info/dependency_links.txt +0 -0
  27. {pum-1.1.17 → pum-1.2.0}/pum.egg-info/entry_points.txt +0 -0
  28. {pum-1.1.17 → pum-1.2.0}/pum.egg-info/requires.txt +0 -0
  29. {pum-1.1.17 → pum-1.2.0}/pum.egg-info/top_level.txt +0 -0
  30. {pum-1.1.17 → pum-1.2.0}/requirements/base.txt +0 -0
  31. {pum-1.1.17 → pum-1.2.0}/requirements/development.txt +0 -0
  32. {pum-1.1.17 → pum-1.2.0}/setup.cfg +0 -0
  33. {pum-1.1.17 → pum-1.2.0}/test/test_changelog.py +0 -0
  34. {pum-1.1.17 → pum-1.2.0}/test/test_dumper.py +0 -0
  35. {pum-1.1.17 → pum-1.2.0}/test/test_schema_migrations.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pum
3
- Version: 1.1.17
3
+ Version: 1.2.0
4
4
  Summary: Pum stands for "Postgres Upgrades Manager". It is a Database migration management tool very similar to flyway-db or Liquibase, based on metadata tables.
5
5
  Author-email: Denis Rouzaud <denis@opengis.ch>
6
6
  License-Expression: GPL-2.0-or-later
@@ -132,11 +132,22 @@ class DemoDataModel(PumCustomBaseModel):
132
132
  DemoDataModel represents a configuration for demo data.
133
133
 
134
134
  Attributes:
135
- files: Optional list of named demo data files.
135
+ name: Name of the demo data.
136
+ file: Optional path to a single demo data file.
137
+ files: Optional list of paths to multiple demo data files.
136
138
  """
137
139
 
138
140
  name: str = Field(..., description="Name of the demo data.")
139
- file: str = Field(..., description="Path to the demo data file.")
141
+
142
+ file: Optional[str] = None
143
+ files: Optional[List[str]] = None
144
+
145
+ @model_validator(mode="after")
146
+ def validate_args(self):
147
+ file, files = self.file, self.files
148
+ if (file and files) or (not file and not files):
149
+ raise PumConfigError("Exactly one of 'file' or 'files' must be set in a demo data set.")
150
+ return self
140
151
 
141
152
 
142
153
  class DependencyModel(PumCustomBaseModel):
@@ -256,9 +256,12 @@ class PumConfig:
256
256
  else []
257
257
  )
258
258
 
259
- def demo_data(self) -> dict[str, str]:
259
+ def demo_data(self) -> dict[str, list[str]]:
260
260
  """Return a dictionary of demo data files defined in the configuration."""
261
- return {dm.name: dm.file for dm in self.config.demo_data}
261
+ demo_data_files = {}
262
+ for dm in self.config.demo_data:
263
+ demo_data_files[dm.name] = dm.files or [dm.file]
264
+ return demo_data_files
262
265
 
263
266
  def __del__(self):
264
267
  # Cleanup temporary directories and sys.path modifications
@@ -125,7 +125,7 @@ class Role:
125
125
  self.inherit = inherit
126
126
  self.description = description
127
127
 
128
- def permissions(self):
128
+ def permissions(self) -> list[Permission]:
129
129
  """
130
130
  Returns the list of permissions associated with the role.
131
131
  """
@@ -138,11 +138,16 @@ class Role:
138
138
  Returns:
139
139
  bool: True if the role exists, False otherwise.
140
140
  """
141
- SqlContent("SELECT 1 FROM pg_roles WHERE rolname = {name}").execute(
142
- connection=connection,
143
- commit=False,
144
- parameters={"name": psycopg.sql.Literal(self.name)},
145
- ).fetchone() is not None
141
+ return (
142
+ SqlContent("SELECT 1 FROM pg_roles WHERE rolname = {name}")
143
+ .execute(
144
+ connection=connection,
145
+ commit=False,
146
+ parameters={"name": psycopg.sql.Literal(self.name)},
147
+ )
148
+ .fetchone()
149
+ is not None
150
+ )
146
151
 
147
152
  def create(
148
153
  self, connection: psycopg.Connection, grant: bool = False, commit: bool = False
@@ -177,9 +177,9 @@ class SchemaMigrations:
177
177
  """
178
178
  if isinstance(version, packaging.version.Version):
179
179
  version = str(version)
180
- pattern = re.compile(r"^\d+\.\d+\.\d+$")
180
+ pattern = re.compile(r"^\d+\.\d+(\.\d+)?$")
181
181
  if not re.match(pattern, version):
182
- raise ValueError(f"Wrong version format: {version}. Must be x.x.x")
182
+ raise ValueError(f"Wrong version format: {version}. Must be x.y or x.y.z")
183
183
 
184
184
  current = self.baseline(connection=connection)
185
185
  if current and current >= version:
@@ -144,8 +144,7 @@ class Upgrader:
144
144
  if name not in self.config.demo_data():
145
145
  raise PumException(f"Demo data '{name}' not found in the configuration.")
146
146
 
147
- demo_data_file = self.config.base_path / self.config.demo_data()[name]
148
- logger.info("Installing demo data from %s", demo_data_file)
147
+ logger.info(f"Installing demo data {name}")
149
148
 
150
149
  for pre_hook in self.config.pre_hook_handlers():
151
150
  pre_hook.execute(connection=connection, commit=False, parameters=parameters)
@@ -153,11 +152,13 @@ class Upgrader:
153
152
  connection.commit()
154
153
 
155
154
  parameters_literals = SqlContent.prepare_parameters(parameters)
156
- SqlContent(sql=demo_data_file).execute(
157
- connection=connection,
158
- commit=False,
159
- parameters=parameters_literals,
160
- )
155
+ for demo_data_file in self.config.demo_data()[name]:
156
+ demo_data_file = self.config.base_path / demo_data_file
157
+ SqlContent(sql=demo_data_file).execute(
158
+ connection=connection,
159
+ commit=False,
160
+ parameters=parameters_literals,
161
+ )
161
162
 
162
163
  connection.commit()
163
164
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pum
3
- Version: 1.1.17
3
+ Version: 1.2.0
4
4
  Summary: Pum stands for "Postgres Upgrades Manager". It is a Database migration management tool very similar to flyway-db or Liquibase, based on metadata tables.
5
5
  Author-email: Denis Rouzaud <denis@opengis.ch>
6
6
  License-Expression: GPL-2.0-or-later
@@ -38,7 +38,7 @@ packages = ["pum"]
38
38
 
39
39
  [tool.setuptools-git-versioning]
40
40
  enabled = true
41
- starting_version = "0.0.0"
41
+ starting_version = "0.1.2"
42
42
 
43
43
  [tool.setuptools.dynamic]
44
44
  readme = {file = ["README.md"], content-type = "text/markdown"}
@@ -6,6 +6,8 @@ from packaging.version import parse as parse_version
6
6
  from pum.pum_config import PumConfig
7
7
  from pum.exceptions import PumConfigError
8
8
  from pum.hook import HookHandler
9
+ import os
10
+ import platform
9
11
 
10
12
 
11
13
  class TestConfig(unittest.TestCase):
@@ -98,6 +100,9 @@ class TestConfig(unittest.TestCase):
98
100
  PumConfig(base_path=Path("test") / "data" / "parameters", validate=True)
99
101
 
100
102
  def test_minimum_version(self) -> None:
103
+ if os.environ.get("CI") and platform.system().lower().startswith("win"):
104
+ self.skipTest("Skipped on Windows in CI")
105
+
101
106
  with self.assertRaises(PumConfigError):
102
107
  PumConfig(
103
108
  base_path=Path("test") / "data" / "single_changelog",
@@ -98,6 +98,20 @@ class TestRoles(unittest.TestCase):
98
98
  )
99
99
  self.assertTrue(cur.fetchone()[0])
100
100
 
101
+ def test_multiple_installs_roles(self) -> None:
102
+ """Test granting permissions to roles."""
103
+ test_dir = Path("test") / "data" / "roles"
104
+ cfg = PumConfig.from_yaml(test_dir / ".pum.yaml")
105
+ with psycopg.connect(f"service={self.pg_service}") as conn:
106
+ Upgrader(cfg).install(connection=conn, roles=True, grant=True, commit=True)
107
+ cur = conn.cursor()
108
+ cur.execute(
109
+ "DROP TABLE public.pum_migrations CASCADE; "
110
+ "DROP SCHEMA pum_test_data_schema_1 CASCADE; "
111
+ "DROP SCHEMA pum_test_data_schema_2 CASCADE;"
112
+ )
113
+ Upgrader(cfg).install(connection=conn, roles=True, grant=True, commit=True)
114
+
101
115
 
102
116
  if __name__ == "__main__":
103
117
  unittest.main()
@@ -407,6 +407,24 @@ class TestUpgrader(unittest.TestCase):
407
407
  count = cursor.fetchone()[0]
408
408
  self.assertEqual(count, 4)
409
409
 
410
+ def test_demo_data_multi(self) -> None:
411
+ """Test the installation of demo data."""
412
+ test_dir = Path("test") / "data" / "demo_data_multi"
413
+ cfg = PumConfig.from_yaml(test_dir / ".pum.yaml")
414
+ sm = SchemaMigrations(cfg)
415
+ with psycopg.connect(f"service={self.pg_service}") as conn:
416
+ self.assertFalse(sm.exists(conn))
417
+ upgrader = Upgrader(config=cfg)
418
+ upgrader.install(connection=conn)
419
+ with self.assertRaises(PumException):
420
+ upgrader.install_demo_data(connection=conn, name="nope, nothing here fella")
421
+ upgrader.install_demo_data(connection=conn, name="some cool demo dataset")
422
+ self.assertTrue(sm.exists(conn))
423
+ cursor = conn.cursor()
424
+ cursor.execute("SELECT COUNT(*) FROM pum_test_data.some_table;")
425
+ count = cursor.fetchone()[0]
426
+ self.assertEqual(count, 4)
427
+
410
428
  def test_dependencies(self) -> None:
411
429
  """Test the installation of dependencies."""
412
430
  test_dir = Path("test") / "data" / "dependencies"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes