Skip to content

Commit

Permalink
Stop recording extension version in dumps.
Browse files Browse the repository at this point in the history
When performing dumps we don't want to include the extension version
as we're not guaranteed that the same version will be avaialble when
restoring the dump.
  • Loading branch information
vpetrovykh committed Feb 7, 2024
1 parent 269cdd7 commit c02db66
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
19 changes: 17 additions & 2 deletions edb/schema/ddl.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,11 +725,13 @@ def ddlast_from_delta(
sdlmode: bool = False,
testmode: bool = False,
descriptive_mode: bool = False,
include_ext_version: bool = True,
) -> Dict[qlast.DDLOperation, sd.Command]:
context = sd.CommandContext(
descriptive_mode=descriptive_mode,
declarative=sdlmode,
testmode=testmode,
include_ext_version=include_ext_version,
)

if schema_a is None:
Expand Down Expand Up @@ -767,6 +769,7 @@ def statements_from_delta(
# Used for backwards compatibility with older migration text.
uppercase: bool = False,
limit_ref_classes: Iterable[so.ObjectMeta] = tuple(),
include_ext_version: bool = True,
) -> Tuple[Tuple[str, qlast.DDLOperation, sd.Command], ...]:

stmts = ddlast_from_delta(
Expand All @@ -775,6 +778,7 @@ def statements_from_delta(
delta,
sdlmode=sdlmode,
descriptive_mode=descriptive_mode,
include_ext_version=include_ext_version,
)

ql_classes_src = {
Expand Down Expand Up @@ -841,6 +845,7 @@ def text_from_delta(
sdlmode: bool = False,
descriptive_mode: bool = False,
limit_ref_classes: Iterable[so.ObjectMeta] = tuple(),
include_ext_version: bool = True,
) -> str:
stmts = statements_from_delta(
schema_a,
Expand All @@ -849,6 +854,7 @@ def text_from_delta(
sdlmode=sdlmode,
descriptive_mode=descriptive_mode,
limit_ref_classes=limit_ref_classes,
include_ext_version=include_ext_version,
)
return '\n'.join(text for text, _, _ in stmts)

Expand All @@ -857,6 +863,8 @@ def ddl_text_from_delta(
schema_a: Optional[s_schema.Schema],
schema_b: s_schema.Schema,
delta: sd.DeltaRoot,
*,
include_ext_version: bool = True,
) -> str:
"""Return DDL text corresponding to a delta plan.
Expand All @@ -872,7 +880,13 @@ def ddl_text_from_delta(
Returns:
DDL text corresponding to *delta*.
"""
return text_from_delta(schema_a, schema_b, delta, sdlmode=False)
return text_from_delta(
schema_a,
schema_b,
delta,
sdlmode=False,
include_ext_version=include_ext_version,
)


def sdl_text_from_delta(
Expand Down Expand Up @@ -954,7 +968,8 @@ def ddl_text_from_schema(
include_derived_types=False,
include_migrations=include_migrations,
)
return ddl_text_from_delta(None, schema, diff)
return ddl_text_from_delta(None, schema, diff,
include_ext_version=not include_migrations)


def sdl_text_from_schema(
Expand Down
2 changes: 2 additions & 0 deletions edb/schema/delta.py
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,7 @@ def __init__(
] = None,
backend_runtime_params: Optional[Any] = None,
compat_ver: Optional[verutils.Version] = None,
include_ext_version: bool = True,
) -> None:
self.stack: List[CommandContextToken[Command]] = []
self._cache: Dict[Hashable, Any] = {}
Expand Down Expand Up @@ -1294,6 +1295,7 @@ def __init__(
List[Tuple[Command, AlterObject[so.Object], List[str]]],
] = collections.defaultdict(list)
self.compat_ver = compat_ver
self.include_ext_version = include_ext_version

@property
def modaliases(self) -> Mapping[Optional[str], str]:
Expand Down
11 changes: 8 additions & 3 deletions edb/schema/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,14 @@ def _get_ast(
assert isinstance(node, qlast.CreateExtension)
pkg = self.get_resolved_attribute_value(
'package', schema=schema, context=context)
node.version = qlast.StringConstant(
value=str(pkg.get_version(schema))
)
# When performing dumps we don't want to include the extension version
# as we're not guaranteed that the same version will be avaialble when
# restoring the dump. We also have no mechanism of installing a specific
# extension version, yet.
if context.include_ext_version:
node.version = qlast.StringConstant(
value=str(pkg.get_version(schema))
)
return node


Expand Down

0 comments on commit c02db66

Please sign in to comment.