MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _init_existing

Method _init_existing

lib/sqlalchemy/sql/schema.py:1136–1200  ·  view source on GitHub ↗
(self, *args: Any, **kwargs: Any)

Source from the content-addressed store, hash-verified

1134 }
1135
1136 def _init_existing(self, *args: Any, **kwargs: Any) -> None:
1137 autoload_with = kwargs.pop("autoload_with", None)
1138 autoload = kwargs.pop("autoload", autoload_with is not None)
1139 autoload_replace = kwargs.pop("autoload_replace", True)
1140 schema = kwargs.pop("schema", None)
1141 _extend_on = kwargs.pop("_extend_on", None)
1142 _reflect_info = kwargs.pop("_reflect_info", None)
1143
1144 # these arguments are only used with _init()
1145 extend_existing = kwargs.pop("extend_existing", False)
1146 keep_existing = kwargs.pop("keep_existing", False)
1147
1148 assert extend_existing
1149 assert not keep_existing
1150
1151 if schema and schema != self.schema:
1152 raise exc.ArgumentError(
1153 f"Can't change schema of existing table "
1154 f"from '{self.schema}' to '{schema}'",
1155 )
1156
1157 include_columns = kwargs.pop("include_columns", None)
1158 if include_columns is not None:
1159 for c in self.c:
1160 if c.name not in include_columns:
1161 self._columns.remove(c)
1162
1163 resolve_fks = kwargs.pop("resolve_fks", True)
1164
1165 for key in ("quote", "quote_schema"):
1166 if key in kwargs:
1167 raise exc.ArgumentError(
1168 "Can't redefine 'quote' or 'quote_schema' arguments"
1169 )
1170
1171 # update `self` with these kwargs, if provided
1172 self.comment = kwargs.pop("comment", self.comment)
1173 self.implicit_returning = kwargs.pop(
1174 "implicit_returning", self.implicit_returning
1175 )
1176 self.info = kwargs.pop("info", self.info)
1177
1178 exclude_columns: _typing_Sequence[str]
1179
1180 if autoload:
1181 if not autoload_replace:
1182 # don't replace columns already present.
1183 # we'd like to do this for constraints also however we don't
1184 # have simple de-duping for unnamed constraints.
1185 exclude_columns = [c.name for c in self.c]
1186 else:
1187 exclude_columns = ()
1188 self._autoload(
1189 self.metadata,
1190 autoload_with,
1191 include_columns,
1192 exclude_columns,
1193 resolve_fks,

Callers 1

_newMethod · 0.80

Calls 5

_autoloadMethod · 0.95
_extra_kwargsMethod · 0.95
_init_itemsMethod · 0.80
popMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected