lamindb_setup 1.9.0__py3-none-any.whl → 1.10.0__py3-none-any.whl

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.
lamindb_setup/__init__.py CHANGED
@@ -35,7 +35,7 @@ Modules & settings:
35
35
 
36
36
  """
37
37
 
38
- __version__ = "1.9.0" # denote a release candidate for 0.1.0 with 0.1rc1
38
+ __version__ = "1.10.0" # denote a release candidate for 0.1.0 with 0.1rc1
39
39
 
40
40
  import os
41
41
 
lamindb_setup/_cache.py CHANGED
@@ -8,6 +8,7 @@ from lamin_utils import logger
8
8
 
9
9
  from .core._settings_save import save_platform_user_storage_settings
10
10
  from .core._settings_store import system_settings_file
11
+ from .errors import CurrentInstanceNotConfigured
11
12
 
12
13
 
13
14
  def clear_cache_dir():
@@ -19,9 +20,8 @@ def clear_cache_dir():
19
20
  "disconnecting the current instance to update the cloud sqlite database."
20
21
  )
21
22
  disconnect()
22
- except SystemExit as e:
23
- if str(e) != "No instance connected! Call `lamin connect` or `lamin init`":
24
- raise e
23
+ except CurrentInstanceNotConfigured:
24
+ pass
25
25
 
26
26
  cache_dir = settings.cache_dir
27
27
  if cache_dir.exists():
@@ -4,7 +4,9 @@ import functools
4
4
  import importlib as il
5
5
  import inspect
6
6
  import os
7
+ from importlib.metadata import distributions
7
8
  from typing import TYPE_CHECKING
9
+ from uuid import UUID
8
10
 
9
11
  from lamin_utils import logger
10
12
 
@@ -25,6 +27,7 @@ if TYPE_CHECKING:
25
27
 
26
28
 
27
29
  CURRENT_ISETTINGS: InstanceSettings | None = None
30
+ MODULE_CANDIDATES: set[str] | None = None
28
31
  IS_LOADING: bool = False
29
32
 
30
33
 
@@ -42,7 +45,25 @@ def disable_auto_connect(func: Callable):
42
45
  return wrapper
43
46
 
44
47
 
45
- def _get_current_instance_settings() -> InstanceSettings | None:
48
+ def find_module_candidates():
49
+ """Find all local packages that depend on lamindb."""
50
+ global MODULE_CANDIDATES
51
+ if MODULE_CANDIDATES is not None:
52
+ return MODULE_CANDIDATES
53
+ all_dists = list(distributions())
54
+ lamindb_deps = {
55
+ dist.metadata["Name"].lower()
56
+ for dist in all_dists
57
+ if dist.requires and any("lamindb" in req.lower() for req in dist.requires)
58
+ }
59
+ lamindb_deps.remove("lamindb")
60
+ MODULE_CANDIDATES = lamindb_deps
61
+ return lamindb_deps
62
+
63
+
64
+ def _get_current_instance_settings(from_module: str | None = None) -> InstanceSettings:
65
+ from .core._settings_instance import InstanceSettings
66
+
46
67
  global CURRENT_ISETTINGS
47
68
 
48
69
  if CURRENT_ISETTINGS is not None:
@@ -60,9 +81,17 @@ def _get_current_instance_settings() -> InstanceSettings | None:
60
81
  " command line: `lamin connect <instance>` or `lamin init <...>`"
61
82
  )
62
83
  raise e
63
- return isettings
64
84
  else:
65
- return None
85
+ module_candidates = find_module_candidates()
86
+ isettings = InstanceSettings(
87
+ id=UUID("00000000-0000-0000-0000-000000000000"),
88
+ owner="none",
89
+ name="none",
90
+ storage=None,
91
+ modules=",".join(module_candidates),
92
+ )
93
+ CURRENT_ISETTINGS = isettings
94
+ return isettings
66
95
 
67
96
 
68
97
  def _normalize_module_name(module_name: str) -> str:
@@ -132,12 +161,7 @@ def _check_instance_setup(from_module: str | None = None) -> bool:
132
161
  return True
133
162
  isettings = _get_current_instance_settings()
134
163
  if isettings is not None:
135
- if (
136
- from_module is not None
137
- and settings.auto_connect
138
- and not django_lamin.IS_SETUP
139
- and not IS_LOADING
140
- ):
164
+ if from_module is not None and not django_lamin.IS_SETUP and not IS_LOADING:
141
165
  if from_module != "lamindb":
142
166
  _check_module_in_instance_modules(from_module, isettings)
143
167
 
@@ -146,13 +170,15 @@ def _check_instance_setup(from_module: str | None = None) -> bool:
146
170
  il.reload(il.import_module(from_module))
147
171
  else:
148
172
  django_lamin.setup_django(isettings)
149
- logger.important(f"connected lamindb: {isettings.slug}")
150
- settings._instance_settings = (
151
- isettings # update of local storage location
152
- )
173
+ if isettings.slug != "none/none":
174
+ logger.important(f"connected lamindb: {isettings.slug}")
175
+ # update of local storage location through search_local_root()
176
+ settings._instance_settings = isettings
177
+ else:
178
+ logger.warning("not connected, call: ln.connect('account/name')")
153
179
  return django_lamin.IS_SETUP
154
180
  else:
155
- if from_module is not None and settings.auto_connect:
181
+ if from_module is not None:
156
182
  # the below enables users to auto-connect to an instance
157
183
  # simply by setting an environment variable, bypassing the
158
184
  # need of calling connect() manually
@@ -2,23 +2,22 @@ from __future__ import annotations
2
2
 
3
3
  import importlib
4
4
  import os
5
+ import sys
5
6
  from typing import TYPE_CHECKING, Any
6
7
  from uuid import UUID
7
8
 
8
9
  from lamin_utils import logger
9
10
 
10
- from ._check_setup import _check_instance_setup, _get_current_instance_settings
11
- from ._disconnect import disconnect
12
- from ._init_instance import (
13
- MESSAGE_CANNOT_SWITCH_DEFAULT_INSTANCE,
14
- load_from_isettings,
11
+ from ._check_setup import (
12
+ _check_instance_setup,
13
+ _get_current_instance_settings,
14
+ find_module_candidates,
15
15
  )
16
+ from ._disconnect import disconnect
17
+ from ._init_instance import load_from_isettings
16
18
  from ._silence_loggers import silence_loggers
17
19
  from .core._hub_core import connect_instance_hub
18
- from .core._hub_utils import (
19
- LaminDsn,
20
- LaminDsnModel,
21
- )
20
+ from .core._hub_utils import LaminDsnModel
22
21
  from .core._settings import settings
23
22
  from .core._settings_instance import InstanceSettings
24
23
  from .core._settings_load import load_instance_settings
@@ -69,21 +68,18 @@ def update_db_using_local(
69
68
  if hub_instance_result["db_scheme"] == "postgresql":
70
69
  if db is not None:
71
70
  # use only the provided db if it is set
72
- db_dsn_hub = LaminDsnModel(db=db)
73
- db_dsn_local = db_dsn_hub
74
- else:
75
- db_dsn_hub = LaminDsnModel(db=hub_instance_result["db"])
71
+ db_updated = db
72
+ elif (db_env := os.getenv("LAMINDB_INSTANCE_DB")) is not None:
73
+ logger.important("loading db URL from env variable LAMINDB_INSTANCE_DB")
76
74
  # read directly from the environment
77
- if os.getenv("LAMINDB_INSTANCE_DB") is not None:
78
- logger.important("loading db URL from env variable LAMINDB_INSTANCE_DB")
79
- db_dsn_local = LaminDsnModel(db=os.getenv("LAMINDB_INSTANCE_DB"))
80
- # read from a cached settings file in case the hub result is only
81
- # read level or inexistent
82
- elif settings_file.exists() and (
83
- db_dsn_hub.db.user in {None, "none"} or "read" in db_dsn_hub.db.user # type:ignore
84
- ):
75
+ db_updated = db_env
76
+ else:
77
+ db_hub = hub_instance_result["db"]
78
+ db_dsn_hub = LaminDsnModel(db=db_hub)
79
+ # read from a cached settings file in case the hub result is inexistent
80
+ if db_dsn_hub.db.user in {None, "none"} and settings_file.exists():
85
81
  isettings = load_instance_settings(settings_file)
86
- db_dsn_local = LaminDsnModel(db=isettings.db)
82
+ db_updated = isettings.db
87
83
  else:
88
84
  # just take the default hub result and ensure there is actually a user
89
85
  if (
@@ -95,22 +91,7 @@ def update_db_using_local(
95
91
  "No database access, please ask your admin to provide you with"
96
92
  " a DB URL and pass it via --db <db_url>"
97
93
  )
98
- db_dsn_local = db_dsn_hub
99
- if not check_db_dsn_equal_up_to_credentials(db_dsn_hub.db, db_dsn_local.db):
100
- raise ValueError(
101
- "The local differs from the hub database information:\n"
102
- "did your database get updated by an admin?\n"
103
- "Consider deleting your cached database environment:\nrm"
104
- f" {settings_file.as_posix()}"
105
- )
106
- db_updated = LaminDsn.build(
107
- scheme=db_dsn_hub.db.scheme,
108
- user=db_dsn_local.db.user,
109
- password=db_dsn_local.db.password,
110
- host=db_dsn_hub.db.host, # type: ignore
111
- port=db_dsn_hub.db.port,
112
- database=db_dsn_hub.db.database,
113
- )
94
+ db_updated = db_hub
114
95
  return db_updated
115
96
 
116
97
 
@@ -127,7 +108,12 @@ def _connect_instance(
127
108
  if settings_file.exists():
128
109
  isettings = load_instance_settings(settings_file)
129
110
  # skip hub request for a purely local instance
130
- make_hub_request = isettings.is_remote
111
+ if isettings.is_remote:
112
+ make_hub_request = True
113
+ else:
114
+ make_hub_request = False
115
+ if db is not None and isettings.dialect == "postgresql":
116
+ isettings._db = db
131
117
  if make_hub_request:
132
118
  # the following will return a string if the instance does not exist
133
119
  # on the hub
@@ -188,6 +174,62 @@ def _connect_instance(
188
174
  return isettings
189
175
 
190
176
 
177
+ def reset_django_module_variables():
178
+ # This function updates all module-level references to Django classes
179
+ # But it will fail to update function level references
180
+ # So, if a user has
181
+ # def my_function():
182
+ # import lamindb as ln
183
+ # ...
184
+ #
185
+ # Then it will **not** work and the `ln` variable will become stale and hold a reference
186
+ # to the old classes
187
+ # There doesn't seem to be an easy way to fix this problem
188
+
189
+ import types
190
+
191
+ from django.apps import apps
192
+
193
+ app_names = {app.name for app in apps.get_app_configs()}
194
+
195
+ for name, module in sys.modules.items():
196
+ if (
197
+ module is not None
198
+ and (not name.startswith("__") or name == "__main__")
199
+ and name not in sys.builtin_module_names
200
+ and not (
201
+ hasattr(module, "__file__")
202
+ and module.__file__
203
+ and any(
204
+ path in module.__file__ for path in ["/lib/python", "\\lib\\python"]
205
+ )
206
+ )
207
+ ):
208
+ try:
209
+ for k, v in vars(module).items():
210
+ if (
211
+ isinstance(v, types.ModuleType)
212
+ and not k.startswith("_")
213
+ and getattr(v, "__name__", None) in app_names
214
+ ):
215
+ if v.__name__ in sys.modules:
216
+ vars(module)[k] = sys.modules[v.__name__]
217
+ # Also reset classes from Django apps - but check if the class module starts with any app name
218
+ elif hasattr(v, "__module__") and getattr(v, "__module__", None):
219
+ class_module = v.__module__
220
+ # Check if the class module starts with any of our app names
221
+ if any(
222
+ class_module.startswith(app_name) for app_name in app_names
223
+ ):
224
+ if class_module in sys.modules:
225
+ fresh_module = sys.modules[class_module]
226
+ attr_name = getattr(v, "__name__", k)
227
+ if hasattr(fresh_module, attr_name):
228
+ vars(module)[k] = getattr(fresh_module, attr_name)
229
+ except (AttributeError, TypeError):
230
+ continue
231
+
232
+
191
233
  def _connect_cli(instance: str) -> None:
192
234
  from lamindb_setup import settings as settings_
193
235
 
@@ -214,6 +256,9 @@ def connect(instance: str | None = None, **kwargs: Any) -> str | tuple | None:
214
256
  instance: Pass a slug (`account/name`) or URL (`https://lamin.ai/account/name`).
215
257
  If `None`, looks for an environment variable `LAMIN_CURRENT_INSTANCE` to get the instance identifier.
216
258
  If it doesn't find this variable, it connects to the instance that was connected with `lamin connect` through the CLI.
259
+
260
+ See Also:
261
+ Configure an instance for auto-connect via the CLI, see `here <https://docs.lamin.ai/cli#connect>`__.
217
262
  """
218
263
  # validate kwargs
219
264
  valid_kwargs = {
@@ -250,19 +295,45 @@ def connect(instance: str | None = None, **kwargs: Any) -> str | tuple | None:
250
295
  "No instance was connected through the CLI, pass a value to `instance` or connect via the CLI."
251
296
  )
252
297
  isettings = isettings_or_none
298
+ if _db is not None and isettings.dialect == "postgresql":
299
+ isettings._db = _db
253
300
  else:
301
+ from django.db import connection
302
+
254
303
  owner, name = get_owner_name_from_identifier(instance)
255
304
  if _check_instance_setup() and not _test:
256
305
  if (
257
306
  settings._instance_exists
258
307
  and f"{owner}/{name}" == settings.instance.slug
308
+ # below is to ensure that if another process interferes
309
+ # we don't use the in-memory mock database
310
+ # could be made more specific by checking whether the django
311
+ # configured database is the same as the one in settings
312
+ and connection.settings_dict["NAME"] != ":memory:"
259
313
  ):
260
- logger.important(f"connected lamindb: {settings.instance.slug}")
314
+ logger.important(
315
+ f"doing nothing, already connected lamindb: {settings.instance.slug}"
316
+ )
261
317
  return None
262
318
  else:
263
- raise CannotSwitchDefaultInstance(
264
- MESSAGE_CANNOT_SWITCH_DEFAULT_INSTANCE
265
- )
319
+ from lamindb_setup.core.django import reset_django
320
+
321
+ if (
322
+ settings._instance_exists
323
+ and settings.instance.slug != "none/none"
324
+ ):
325
+ import lamindb as ln
326
+
327
+ if ln.context.transform is not None:
328
+ raise CannotSwitchDefaultInstance(
329
+ "Cannot switch default instance while `ln.track()` is live: call `ln.finish()`"
330
+ )
331
+ else:
332
+ logger.important_hint(
333
+ "switching the default lamindb instance might produce unexpected side effects with function-scoped imports: "
334
+ "please import lamindb at the module level instead of inside functions"
335
+ )
336
+ reset_django()
266
337
  elif (
267
338
  _write_settings
268
339
  and settings._instance_exists
@@ -315,7 +386,9 @@ def connect(instance: str | None = None, **kwargs: Any) -> str | tuple | None:
315
386
  load_from_isettings(isettings, user=_user, write_settings=_write_settings)
316
387
  if _reload_lamindb:
317
388
  importlib.reload(importlib.import_module("lamindb"))
318
- logger.important(f"connected lamindb: {isettings.slug}")
389
+ reset_django_module_variables()
390
+ if isettings.slug != "none/none":
391
+ logger.important(f"connected lamindb: {isettings.slug}")
319
392
  except Exception as e:
320
393
  if isettings is not None:
321
394
  if _write_settings:
lamindb_setup/_delete.py CHANGED
@@ -65,6 +65,9 @@ def delete(slug: str, force: bool = False, require_empty: bool = True) -> int |
65
65
  If the instance is owned by you, it suffices to pass the instance name.
66
66
  force: Whether to skip the confirmation prompt.
67
67
  require_empty: Whether to check if the instance is empty before deleting.
68
+
69
+ See Also:
70
+ Delete an instance via the CLI, see `here <https://docs.lamin.ai/cli#delete>`__.
68
71
  """
69
72
  owner, name = get_owner_name_from_identifier(slug)
70
73
  isettings = _connect_instance(owner, name, raise_permission_error=False)
@@ -8,9 +8,12 @@ from .core.cloud_sqlite_locker import clear_locker
8
8
 
9
9
 
10
10
  def disconnect(mute: bool = False) -> None:
11
- """Disconnect an instance.
11
+ """Clear default instance configuration.
12
12
 
13
13
  Returns `None` if succeeds, otherwise an exception is raised.
14
+
15
+ See Also:
16
+ Clear default instance configuration via the CLI, see `here <https://docs.lamin.ai/cli#disconnect>`__.
14
17
  """
15
18
  if current_instance_settings_file().exists():
16
19
  instance = settings.instance.slug
@@ -16,7 +16,7 @@ from ._silence_loggers import silence_loggers
16
16
  from .core import InstanceSettings
17
17
  from .core._docs import doc_args
18
18
  from .core._settings import settings
19
- from .core._settings_instance import is_local_db_url
19
+ from .core._settings_instance import check_is_instance_remote, is_local_db_url
20
20
  from .core._settings_storage import StorageSettings, init_storage
21
21
  from .core.upath import UPath
22
22
  from .errors import CannotSwitchDefaultInstance
@@ -215,16 +215,6 @@ def validate_init_args(
215
215
  return name_str, instance_id, instance_state, instance_slug
216
216
 
217
217
 
218
- MESSAGE_CANNOT_SWITCH_DEFAULT_INSTANCE = """
219
- You cannot write to different instances in the same Python session.
220
-
221
- Do you want to read from another instance via `SQLRecord.using()`? For example:
222
-
223
- ln.Artifact.using("laminlabs/cellxgene").filter()
224
-
225
- Or do you want to switch off auto-connect via `lamin settings set auto-connect false`?
226
- """
227
-
228
218
  DOC_STORAGE_ARG = "A local or remote folder (`'s3://...'` or `'gs://...'`). Defaults to current working directory."
229
219
  DOC_INSTANCE_NAME = (
230
220
  "Instance name. If not passed, it will equal the folder name passed to `storage`."
@@ -251,6 +241,9 @@ def init(
251
241
  db: {}
252
242
  modules: {}
253
243
  **kwargs: {}
244
+
245
+ See Also:
246
+ Init an instance for via the CLI, see `here <https://docs.lamin.ai/cli#init>`__.
254
247
  """
255
248
  isettings = None
256
249
  ssettings = None
@@ -272,9 +265,16 @@ def init(
272
265
  from ._check_setup import _check_instance_setup
273
266
 
274
267
  if _check_instance_setup() and not _test:
275
- raise CannotSwitchDefaultInstance(MESSAGE_CANNOT_SWITCH_DEFAULT_INSTANCE)
268
+ from lamindb_setup.core.django import reset_django
269
+
270
+ if settings._instance_exists:
271
+ raise CannotSwitchDefaultInstance(
272
+ "Cannot init new instance after connecting to an existing instance."
273
+ )
274
+ reset_django()
276
275
  elif _write_settings:
277
276
  disconnect(mute=True)
277
+ from ._connect_instance import reset_django_module_variables
278
278
  from .core._hub_core import init_instance_hub
279
279
 
280
280
  name_str, instance_id, instance_state, _ = validate_init_args(
@@ -287,44 +287,38 @@ def init(
287
287
  _user=_user, # will get from settings.user if _user is None
288
288
  )
289
289
  if instance_state == "connected":
290
- if _write_settings:
291
- settings.auto_connect = True # we can also debate this switch here
292
290
  return None
293
- prevent_register_hub = is_local_db_url(db) if db is not None else False
294
- ssettings, _ = init_storage(
295
- storage,
296
- instance_id=instance_id,
297
- instance_slug=f"{user_handle}/{name_str}",
298
- init_instance=True,
299
- prevent_register_hub=prevent_register_hub,
300
- created_by=user__uuid,
301
- access_token=access_token,
302
- )
303
291
  isettings = InstanceSettings(
304
292
  id=instance_id, # type: ignore
305
293
  owner=user_handle,
306
294
  name=name_str,
307
- storage=ssettings,
308
295
  db=db,
309
296
  modules=modules,
310
- uid=ssettings.uid,
311
297
  # to lock passed user in isettings._cloud_sqlite_locker.lock()
312
298
  _locker_user=_user, # only has effect if cloud sqlite
313
299
  )
314
300
  register_on_hub = (
315
- isettings.is_remote and instance_state != "instance-corrupted-or-deleted"
301
+ check_is_instance_remote(root=storage, db=db)
302
+ and instance_state != "instance-corrupted-or-deleted"
316
303
  )
317
304
  if register_on_hub:
318
- # can't register the instance in the hub
319
- # if storage is not in the hub
320
- # raise the exception and initiate cleanups
321
- if not isettings.storage.is_on_hub:
322
- raise InstanceNotCreated(
323
- "Unable to create the instance because failed to register the storage."
324
- )
325
305
  init_instance_hub(
326
306
  isettings, account_id=user__uuid, access_token=access_token
327
307
  )
308
+ ssettings, _ = init_storage(
309
+ storage,
310
+ instance_id=instance_id,
311
+ instance_slug=f"{user_handle}/{name_str}",
312
+ init_instance=True,
313
+ register_hub=register_on_hub,
314
+ created_by=user__uuid,
315
+ access_token=access_token,
316
+ )
317
+ isettings._storage = ssettings
318
+ if register_on_hub and not ssettings.is_on_hub:
319
+ raise InstanceNotCreated(
320
+ "Unable to create the instance because failed to register the storage."
321
+ )
328
322
  validate_sqlite_state(isettings)
329
323
  # why call it here if it is also called in load_from_isettings?
330
324
  isettings._persist(write_to_disk=_write_settings)
@@ -344,9 +338,8 @@ def init(
344
338
  from ._schema_metadata import update_schema_in_hub
345
339
 
346
340
  update_schema_in_hub(access_token=access_token)
347
- if _write_settings:
348
- settings.auto_connect = True
349
341
  importlib.reload(importlib.import_module("lamindb"))
342
+ reset_django_module_variables()
350
343
  logger.important(f"initialized lamindb: {isettings.slug}")
351
344
  except Exception as e:
352
345
  from ._delete import delete_by_isettings
@@ -357,16 +350,10 @@ def init(
357
350
  delete_by_isettings(isettings)
358
351
  else:
359
352
  settings._instance_settings = None
360
- if (
361
- ssettings is not None
362
- and (user_handle != "anonymous" or access_token is not None)
363
- and ssettings.is_on_hub
364
- ):
365
- delete_storage_record(ssettings, access_token=access_token) # type: ignore
366
- if isettings is not None:
367
- if (
368
- user_handle != "anonymous" or access_token is not None
369
- ) and isettings.is_on_hub:
353
+ if user_handle != "anonymous" or access_token is not None:
354
+ if ssettings is not None and ssettings.is_on_hub:
355
+ delete_storage_record(ssettings, access_token=access_token)
356
+ if isettings is not None and isettings.is_on_hub:
370
357
  delete_instance_record(isettings._id, access_token=access_token)
371
358
  raise e
372
359
  return None
@@ -400,6 +387,9 @@ def load_from_isettings(
400
387
  # this is blocked anyways, only select and insert are allowed
401
388
  register_user(user, update_user=not isettings._fine_grained_access)
402
389
  isettings._persist(write_to_disk=write_settings)
390
+ # clear branch & space cache after reconnecting
391
+ settings._branch = None
392
+ settings._space = None
403
393
 
404
394
 
405
395
  def validate_sqlite_state(isettings: InstanceSettings) -> None:
lamindb_setup/_migrate.py CHANGED
@@ -63,16 +63,29 @@ def check_whether_migrations_in_sync(db_version_str: str):
63
63
  # logger.important("consider migrating your database: lamin migrate deploy")
64
64
 
65
65
 
66
- # for tests, see lamin-cli
67
66
  class migrate:
68
- """Manage migrations.
67
+ """Manage database migrations.
68
+
69
+ Unless you maintain your own schema modules with your own Django models, you won't need this.
69
70
 
70
71
  Examples:
71
72
 
72
- >>> import lamindb as ln
73
- >>> ln.setup.migrate.create()
74
- >>> ln.setup.migrate.deploy()
75
- >>> ln.setup.migrate.check()
73
+ Create a migration::
74
+
75
+ import lamindb as ln
76
+
77
+ ln.setup.migrate.create()
78
+
79
+ Deploy a migration::
80
+
81
+ ln.setup.migrate.deploy()
82
+
83
+ Check migration consistency::
84
+
85
+ ln.setup.migrate.check()
86
+
87
+ See Also:
88
+ Migrate an instance via the CLI, see `here <https://docs.lamin.ai/cli#migrate>`__.
76
89
 
77
90
  """
78
91
 
@@ -85,7 +98,6 @@ class migrate:
85
98
  setup_django(settings.instance, create_migrations=True)
86
99
 
87
100
  @classmethod
88
- @disable_auto_connect
89
101
  def deploy(cls, package_name: str | None = None, number: int | None = None) -> None:
90
102
  """Deploy a migration."""
91
103
  from ._schema_metadata import update_schema_in_hub
@@ -21,12 +21,9 @@ def register(_test: bool = False):
21
21
  ssettings = settings.instance.storage
22
22
  if ssettings._uid is None and _test:
23
23
  # because django isn't up, we can't get it from the database
24
- ssettings._uid = base62(8)
25
- # cannot yet populate the instance id here
26
- ssettings._instance_id = None
27
- # flag auto_populate_instance can be removed once FK migration is over
28
- init_storage_hub(ssettings, auto_populate_instance=False)
24
+ ssettings._uid = base62(12)
29
25
  init_instance_hub(isettings)
26
+ init_storage_hub(ssettings, is_default=True)
30
27
  isettings._is_on_hub = True
31
28
  isettings._persist()
32
29
  if isettings.dialect != "sqlite" and not _test:
@@ -49,7 +49,6 @@ def set_managed_storage(root: UPathStr, host: str | None = None, **fs_kwargs):
49
49
  instance_id=settings.instance._id,
50
50
  instance_slug=settings.instance.slug,
51
51
  register_hub=settings.instance.is_on_hub,
52
- prevent_register_hub=not settings.instance.is_on_hub,
53
52
  region=host,
54
53
  )
55
54
  if ssettings._instance_id is None: