Skip to content

Commit 584b445

Browse files
committed
Merge branch 'm-kovalsky/sql_database'
2 parents be7fc73 + 1bc65f5 commit 584b445

File tree

4 files changed

+100
-12
lines changed

4 files changed

+100
-12
lines changed

src/sempy_labs/__init__.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,6 @@
196196
ConnectLakehouse,
197197
ConnectSQLDatabase,
198198
)
199-
from ._sqldatabase import (
200-
get_sql_database_columns,
201-
get_sql_database_tables,
202-
create_sql_database,
203-
delete_sql_database,
204-
list_sql_databases,
205-
)
206199
from ._workspace_identity import (
207200
provision_workspace_identity,
208201
deprovision_workspace_identity,
@@ -559,8 +552,6 @@
559552
"get_eventhouse_definition",
560553
"enable_semantic_model_scheduled_refresh",
561554
"get_delta_table_history",
562-
"get_sql_database_columns",
563-
"get_sql_database_tables",
564555
"create_item_schedule_cron",
565556
"create_item_schedule_daily",
566557
"create_item_schedule_weekly",
@@ -571,9 +562,6 @@
571562
"delete_mounted_data_factory",
572563
"delete_semantic_model",
573564
"delete_workspace",
574-
"create_sql_database",
575-
"delete_sql_database",
576-
"list_sql_databases",
577565
"delta_analyzer_history",
578566
"query_kusto",
579567
"query_workspace_monitoring",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from sempy_labs.sql_database._items import (
2+
get_sql_database_columns,
3+
get_sql_database_tables,
4+
create_sql_database,
5+
delete_sql_database,
6+
list_sql_databases,
7+
)
8+
from sempy_labs.sql_database._mirroring import (
9+
start_mirroring,
10+
stop_mirroring,
11+
)
12+
13+
__all__ = [
14+
"get_sql_database_columns",
15+
"get_sql_database_tables",
16+
"create_sql_database",
17+
"delete_sql_database",
18+
"list_sql_databases",
19+
"start_mirroring",
20+
"stop_mirroring",
21+
]
File renamed without changes.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
from sempy_labs._helper_functions import (
2+
resolve_item_id,
3+
_base_api,
4+
resolve_workspace_name_and_id,
5+
)
6+
from typing import Optional
7+
from uuid import UUID
8+
from sempy._utils._log import log
9+
import sempy_labs._icons as icons
10+
11+
12+
@log
13+
def start_mirroring(sql_database: str | UUID, workspace: Optional[str | UUID] = None):
14+
"""
15+
Starts data mirroring for the specified SQL Database.
16+
17+
This is a wrapper function for the following API: `Mirroring - Start Mirroring <https://learn.microsoft.com/rest/api/fabric/sqldatabase/mirroring/start-mirroring>`_.
18+
19+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
20+
21+
Parameters
22+
----------
23+
sql_database : str | uuid.UUID
24+
Name or ID of the SQL Database.
25+
workspace : str | uuid.UUID, default=None
26+
The Fabric workspace name or ID.
27+
Defaults to None which resolves to the workspace of the attached lakehouse
28+
or if no lakehouse attached, resolves to the workspace of the notebook.
29+
"""
30+
31+
(workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace)
32+
item_id = resolve_item_id(
33+
item=sql_database, type="SQLDatabase", workspace=workspace_id
34+
)
35+
36+
_base_api(
37+
request=f"/v1/workspaces/{workspace_id}/sqlDatabases/{item_id}/startMirroring",
38+
method="post",
39+
client="fabric_sp",
40+
)
41+
42+
print(
43+
f"{icons.green_dot} The SQL Database '{sql_database}' in the '{workspace_name}' workspace is now being mirrored."
44+
)
45+
46+
47+
@log
48+
def stop_mirroring(sql_database: str | UUID, workspace: Optional[str | UUID] = None):
49+
"""
50+
Stops data mirroring for the specified SQL Database.
51+
52+
This is a wrapper function for the following API: `Mirroring - Stop Mirroring <https://learn.microsoft.com/rest/api/fabric/sqldatabase/mirroring/stop-mirroring>`_.
53+
54+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
55+
56+
Parameters
57+
----------
58+
sql_database : str | uuid.UUID
59+
Name or ID of the SQL Database.
60+
workspace : str | uuid.UUID, default=None
61+
The Fabric workspace name or ID.
62+
Defaults to None which resolves to the workspace of the attached lakehouse
63+
or if no lakehouse attached, resolves to the workspace of the notebook.
64+
"""
65+
66+
(workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace)
67+
item_id = resolve_item_id(
68+
item=sql_database, type="SQLDatabase", workspace=workspace_id
69+
)
70+
71+
_base_api(
72+
request=f"/v1/workspaces/{workspace_id}/sqlDatabases/{item_id}/stopMirroring",
73+
method="post",
74+
client="fabric_sp",
75+
)
76+
77+
print(
78+
f"{icons.green_dot} The SQL Database '{sql_database}' in the '{workspace_name}' workspace is no longer being mirrored."
79+
)

0 commit comments

Comments
 (0)