Skip to content

Commit

Permalink
Add missing migration script. (Issue #6549, PR #6596)
Browse files Browse the repository at this point in the history
# Description

Previous PR was missing a migration script

closes #6549

# Self Check:

Strike through any lines that are not applicable (`~~line~~`) then check the box

- [ ] Attached issue to pull request
- [ ] Changelog entry
- [ ] Type annotations are present
- [ ] Code is clear and sufficiently documented
- [ ] No (preventable) type errors (check using make mypy or make mypy-diff)
- [ ] Sufficient test cases (reproduces the bug/tests the requested feature)
- [ ] Correct, in line with design
- [ ] End user documentation is included or an issue is created for end-user documentation (add ref to issue here: )
- [ ] If this PR fixes a race condition in the test suite, also push the fix to the relevant stable branche(s) (see [test-fixes](https://internal.inmanta.com/development/core/tasks/build-master.html#test-fixes) for more info)
  • Loading branch information
Hugo-Inmanta authored and inmantaci committed Oct 10, 2023
1 parent ecc9ede commit ba616b3
Show file tree
Hide file tree
Showing 8 changed files with 1,562 additions and 4 deletions.
4 changes: 4 additions & 0 deletions changelogs/unreleased/6549-add-missing-migration-script.yml
@@ -0,0 +1,4 @@
description: Add missing migration script.
issue-nr: 6549
change-type: patch
destination-branches: [master, iso6]
1 change: 0 additions & 1 deletion src/inmanta/data/__init__.py
Expand Up @@ -2816,7 +2816,6 @@ async def set(
RETURNING settings
"""
values = [allow_override, self._get_value(key), self._get_value([key]), self._get_value(value)] + values

new_value = await self._fetchval(query, *values, connection=connection)
new_value_parsed = cast(
Dict[str, m.EnvSettingType], self.get_field_metadata()["settings"].from_db(name="settings", value=new_value)
Expand Down
3 changes: 2 additions & 1 deletion src/inmanta/data/model.py
Expand Up @@ -25,6 +25,7 @@
import pydantic.schema
from pydantic import Extra, root_validator, validator
from pydantic.fields import ModelField
from pydantic.types import StrictFloat, StrictInt, StrictStr

import inmanta
import inmanta.ast.export as ast_export
Expand Down Expand Up @@ -234,7 +235,7 @@ def check_serializable(cls, v: Optional[Any]) -> Optional[Any]:
return v


EnvSettingType = Union[StrictNonIntBool, int, float, str, Dict[str, Union[str, int, StrictNonIntBool]]]
EnvSettingType = Union[StrictNonIntBool, StrictInt, StrictFloat, StrictStr, Dict[str, Union[str, int, StrictNonIntBool]]]


class Environment(BaseModel):
Expand Down
37 changes: 37 additions & 0 deletions src/inmanta/db/versions/v202310090.py
@@ -0,0 +1,37 @@
"""
Copyright 2023 Inmanta
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Contact: code@inmanta.com
"""
from asyncpg import Connection

from inmanta import data


def convert_setting_to_str(setting: str) -> str:
# The ->> operator gets the JSON object field as text
return f"""
UPDATE environment
SET settings=jsonb_set(settings, '{{{setting}}}'::TEXT[], to_jsonb(settings->>'{setting}'), FALSE)
WHERE settings ? '{setting}'
"""


async def update(connection: Connection) -> None:
"""
Update the type of the autostart_agent_repair_interval and autostart_agent_deploy_interval from int to str
"""
await connection.execute(convert_setting_to_str(data.AUTOSTART_AGENT_REPAIR_INTERVAL))
await connection.execute(convert_setting_to_str(data.AUTOSTART_AGENT_DEPLOY_INTERVAL))
4 changes: 2 additions & 2 deletions tests/db/migration_tests/dump_tool.py
Expand Up @@ -67,9 +67,9 @@ async def test_dump_db(server, client, postgres_db, database_name):
shutil.copytree(project_source, project_dir)

check_result(await client.set_setting(env_id_1, "autostart_agent_deploy_splay_time", 0))
check_result(await client.set_setting(env_id_1, "autostart_agent_deploy_interval", 0))
check_result(await client.set_setting(env_id_1, "autostart_agent_deploy_interval", "0"))
check_result(await client.set_setting(env_id_1, "autostart_agent_repair_splay_time", 0))
check_result(await client.set_setting(env_id_1, "autostart_agent_repair_interval", 600))
check_result(await client.set_setting(env_id_1, "autostart_agent_repair_interval", "600"))
check_result(await client.set_setting(env_id_1, "auto_deploy", False))

await client.notify_change(id=env_id_1)
Expand Down

0 comments on commit ba616b3

Please sign in to comment.