Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/6549 add missing migration script #6596

Closed
wants to merge 15 commits into from
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]]]
arnaudsjs marked this conversation as resolved.
Show resolved Hide resolved


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