Connections and safety

функциональный

Per-cell connections, environment badges, read-only by default, Allow writes, production prompts, trusting a notebook and remapping connections.

A notebook from another computer opens behind the trust banner; trusting it read-only; a cell whose SQL changes data stays blocked until Allow writes; a shared notebook asks to map its connections.

Real recording · typing sped up · Northwind demo data

Open the walkthrough on its own page

Every SQL cell runs on a connection: the notebook's, or one of its own. Whichever it is, the cell shows the connection and its environment, starts read-only, and needs your explicit go-ahead to change data. A notebook from somewhere else runs nothing until you trust it and say which connections it may use.

Per-cell connections

The top bar's Connection: … picker sets the notebook's connection; new cells use it. To run one cell somewhere else, select it and pick a connection in the inspector's Подключение field (or from the connection label in the cell header). Use the notebook's connection puts it back; a cell that follows the notebook shows its connection as "Storefront Dev (notebook)".

Each connection shows its environment badge, the same colours as the rest of SQLly: Продакшн, Тестирование, Тест, Разработка или Локально, set on the connection itself (see Окружения). A notebook can compare development with production side by side, with each cell saying exactly where it ran.

SQLly
Cell inspector connection picker listing connections with environment badgesCell inspector connection picker listing connections with environment badges
A cell's connection picker in the inspector, with the Production badge on the production connection.

Inside the file, a notebook refers to connections by slot: an id of its own, mapped to your saved connection by an opaque id. Server names, users and passwords are never written into a notebook. To read a result from a cell on a different connection, run the reading cell on the notebook's local data; see Join across connections.

Read-only by default

A new SQL cell is Только для чтения. It runs on a copy of its connection with SQLly's read-only setting switched on, and on engines that have one, inside the database's own read-only session or transaction, so a statement that tries to write fails in the database even if SQLly's own check missed it. A read-only cell whose SQL plainly changes data is stopped before it is sent: "This cell is read-only and its SQL changes data. Choose Allow writes to run it."

Other kinds of cell that query a connection follow the same rule, with a few extra checks:

  • Plan cells always capture their plan read-only, estimated or actual, and only for a single statement: "A plan can only be captured for a single statement. Split the query into one statement per cell." A query picked for comparison passes the same checks and must be on the same connection.
  • Local cells and Materialize Locally never run a cell that may change data again to copy its rows. They use the complete result already on screen, or say "fix_freight changes data, so it is not run again to copy its rows. Run it yourself, then copy its complete result." Every other input they fetch again runs read-only.
  • Diff cells that re-run a query on another connection need that connection allowed for the notebook and set up on this computer.

Results are filed under the connection, database, login and safety settings that fetched them. Switch a connection's sign-in, or its read-only setting, and earlier results are no longer current and saved ones aren't shown to the new login.

Cells in a notebook from an older SQLly version (.sqlnb.json) that change data come in with writes already allowed, so they keep working as they did; every cell you add starts read-only.

Allow writes

  1. Нажмите Allow writes in the cell header (or clear Только для чтения in the inspector, or run Notebook: Allow Writes for Cell from the palette).
  2. SQLly asks "Let fix_freight change data?" and names the connection the cell runs on. On a production connection it adds "This is a production connection." Choose Allow writes, или Keep read-only.
  3. The badge changes to Writes allowed, с Make read-only next to it to undo.
  4. When the cell runs, its statements still go through SQLly's change review, which says which connection and environment the change goes to ("On Storefront Prod (Production): …") and applies the connection's own rules: confirmation, refusing UPDATE or DELETE without WHERE, the production lock. The cell waits as Waiting for review until you answer.
SQLly
Prompt asking whether a cell may change data on a production connectionPrompt asking whether a cell may change data on a production connection
Allow writes on a production cell: the prompt names the connection and calls out production before anything can change.

A cell that changes data runs alone on its connection (the cells before it finish first), and notebooks with such cells can't be scheduled, viewed as a dashboard or presented. See Безопасность и защитные механизмы for the connection-level settings the change review uses.

Trusting a notebook

Opening a notebook never runs anything. When a notebook came from somewhere else (another computer, a colleague, Git, Jupyter), or its queries or connections changed outside SQLly since you trusted it, a banner says so and nothing runs:

  • "This notebook came from somewhere else. Nothing runs until you trust it and choose the connections it may use."
  • "This notebook's queries or connections changed outside SQLLY since you trusted it. Review it and trust it again to run it."
  1. Read the cells. Everything is visible and editable before you trust.
  2. Нажмите Trust notebook on the banner (or Notebook: Trust Notebook in the palette).
  3. В Trust this notebook, check the connections under Connections it may use. Each line shows the connection on this computer it runs on and that connection's environment. Untick any the notebook shouldn't use.
  4. Выберите Trust (cells may run on the ticked connections) or Read-only trust (only cells that don't change data may run).
  5. Отметить Allow cells that change data only if the notebook needs it. It starts unticked for a notebook from elsewhere.
  6. Нажмите Trust.
SQLly
Trust this notebook dialogTrust this notebook dialog
The trust dialog lists each connection with the local connection it maps to, full or read-only trust, and whether cells that change data may run.

After that, the notebook stays trusted while you edit and save it in SQLly. Editing its Markdown or title elsewhere keeps it trusted; changing its SQL, its connections or a cell's read-only setting outside SQLly makes it untrusted again. A cell on a connection you unticked doesn't run, and the banner lists the connections still waiting ("This notebook isn't allowed to use these connections yet: …") with Allow connections. Under read-only trust the banner says "Trusted for read-only runs: cells that change data won't run." with Change trust.

More on what trust covers and how it's stored: Security model.

Remapping connections

A notebook made on another computer names connections by that computer's ids, which mean nothing here. SQLly shows "This notebook uses connections that are not on this computer. Choose one of yours for each:" with a Choose a connection picker per connection (labelled with the name and database the author used), and Skip for now. A cell whose connection isn't mapped shows Not on this computer and won't run until you map it.

SQLly
Prompt to map a notebook's connections to local connectionsPrompt to map a notebook's connections to local connections
A shared notebook whose connections don't exist here: map each one to a local connection.

Mapping is saved in the notebook when you save it. A connection you remap after trusting the notebook waits for your OK again, so pointing a notebook at production is always a decision you make, not a side effect of someone else's edit.

Ограничения

  • Whether SQL "changes data" is judged from its statements; a procedure call that writes can look like a read. The database's read-only session is the real guard for read-only cells, and connections marked read-only in SQLly stay read-only whatever a notebook says.
  • "Use the tab's connection" in the top bar's connection menu moves every cell that follows the notebook's connection onto the tab's. While a cell is set to some other connection, it's refused ("Some cells use another connection, so the notebook keeps its saved connection. Set those cells to the notebook's connection first."), because that connection would otherwise become every cell's default.