Skip to content

RESTORE DATABASE to a `timestamp` (each table as of its last version committed at or before it) or

POST
/datanotes/operations/restore_database/
curl --request POST \
--url https://example.com/datanotes/operations/restore_database/ \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'X-Datanotes-Actor: {"harness":"my-script","model":"","session":"s-1"}' \
--data '{ "timestamp": null, "before_migration": null, "dry_run": false }'

RESTORE DATABASE to a timestamp (each table as of its last version committed at or before it) or to before_migration (a migration_id or a batch: every table as it was just before that operation ran — to rewind an agent’s run). Every table that keeps a transaction log goes back, rows and definition: rows added since are deleted, changed rows get their old content, removed rows come back; a table created since is dropped with its rows moved to its archive folder (as drop_table with mode “archive”: nothing is hard-deleted), a table dropped since comes back. Tables already as they were are left alone (unchanged, no new version). One operation: each restored table gets a RESTORE version, all with one migration_id, and undo_migration on it reverts them all. Refused as a whole, nothing written (rows listed, with the way out), when a row it leaves would break a CHECK that follows links or a ref_where / ref_by, across tables, as the restored definitions have them. Tables without a log (history off, or vacuumed before that time) cannot be rewound: they stay as they are, listed in skipped with the reason (tell the user). Views, bases and the database settings are not rewound (the logs keep tables), nor a rename or move of a table (undo_migration on it does that). Returns restored_to, tables (per table: action restore / drop / recreate, version, creates, texts, deletes, archived), unchanged and skipped. Run with dry_run first and show the user what changes; describe_history without table shows the moments.

The schema changes only through operations like this one: never edit metastore.yaml by hand (no validation, no undo).

X-Datanotes-Actor
string

JSON: on whose behalf the write is made, recorded in the journal (harness, model, session).

Example

{"harness":"my-script","model":"","session":"s-1"}
Media typeapplication/json
object
timestamp
Any of:
string
before_migration
Any of:
string
dry_run
boolean

Done.

Media typeapplication/json
RestoreDatabaseResult

Result of restore_database: a write operation’s result plus what it does to each table. A refusal (ok false) is answered with HTTP 422, a failed write with 500, so a 2xx body has ok true.

object
ok
required

True when the operation was applied (or, on a dry run, would be).

boolean
op
required

The operation, by the name it was called with (e.g. insert_row, create_table, recompute_columns).

string
dry_run
required

True when nothing was written (preview).

boolean
migration_id

Journal id of the applied operation: pass it to undo_migration. Absent on a dry run.

string
notes_changed
required

Notes whose front matter or body were written.

integer
files_created
required

Files created.

integer
files_moved
required

Files moved or renamed.

integer
files_deleted
required

Files deleted or archived.

integer
references_updated
required

Links rewritten in other notes.

integer
conflicts
required

Reasons the operation was refused (empty on success).

Array<object>
object
path
required

Note or file path.

string
message
required

Why the operation cannot proceed.

string
violations
required

Rows that would break the table’s rules (empty on success).

Array<object>
RowViolations

The violations of one row.

object
path
required

Row note path.

string
violations
required

What is wrong with this row.

Array<object>
Violation
object
column

The column the violation is about (every code but check and unreadable).

string
index

The item of a list column that breaks the rule, from 0.

integer
constraint

The CHECK’s name (code check).

string
code
required

Kind of violation.

string
Allowed values: required inverse type min max step enum broken_link ref unique unknown_column check generated cycle vocabulary unreadable
message
required

Agent-readable explanation.

string
value

The offending value, when there is one.

failed
required

Files that could not be written (empty on success).

Array<object>
object
path
required

Vault path.

string
error
required

What went wrong.

string
rolled_back

Set when a write failed partway (failed): true when the engine put back what it had written, so nothing is left written; false when that rollback failed too (failed names the files left, and undo_migration on migration_id retries it).

boolean
planned_edits
required

Front matter edits per note (planned, or made).

Array<object>
object
path
required

Note path.

string
set
required

Front matter keys set, with their new values.

object
key
additional properties
any
remove
required

Front matter keys removed.

Array<string>
body

True when the note body changes too.

boolean
planned_creates
required

Paths of notes created.

Array<string>
planned_moves
required

Files moved: from → to.

Array<object>
object
from
required
string
to
required
string
planned_deletes
required

Paths deleted (or archived).

Array<string>
planned_texts
required

Files rewritten whole, e.g. metastore.yaml for DDL.

Array<string>
commits

Transaction-log commits written (tables with history on).

Array<object>
object
table
required

Qualified table.

string
version
required

New log version.

integer
operation
required

Log operation, e.g. WRITE.

string
links_added

Links the write added to the text it wrote: the notes the text mentions by name (automatic links). Present when there is one.

Array<object>
LinkAdded

A link the write added in place of a mention.

object
path
required

The note the link was written into.

string
text
required

The mention, as written.

string
target
required

Vault path of the note it links.

string
link
required

The link written in place of the mention.

string
ambiguous_mentions

Mentions left as text because the engine is not sure which note they name. Present when there is one: read the candidates and the context, then link the right one with update_row and autolink: false, or leave the text.

Array<object>
LinkAmbiguous

A mention left as text: more than one note could be meant.

object
path
required

The note the mention is in.

string
text
required

The mention, as written.

string
reason
required

Same_name: several notes have this name; adjacent: names of different notes side by side, which may be one name; overlap: names of notes overlap; part_of_name: a capitalized word next to it suggests a longer name; sentence_start: a one-word name at the start of a sentence, a line, a list item or a label, where its capital says nothing.

string
Allowed values: same_name adjacent overlap part_of_name sentence_start
candidates
required

Vault paths of the notes it may name.

Array<string>
context
required

The line around the mention.

string
hint
required

What to do: read the candidates, then link the right one with update_row and autolink: false, or leave the text.

string
restored_to
required

The moment restored (ISO date-time): timestamp, or the last millisecond before the first commit of before_migration; given back as timestamp, it names the same state.

string
tables
required

The tables that change.

Array<object>
object
table
required

Qualified table.

string
action
required

Restore: rows and/or definition go back; drop: the table did not exist then (definition removed, rows archived); recreate: dropped since, it comes back.

string
Allowed values: restore drop recreate
version
required
Any of:
integer
definition_changed
required

Its entry in metastore.yaml changes.

boolean
creates
required

Rows re-created.

Array<string>
texts
required

Rows that get their old text back.

Array<string>
deletes
required

Rows created since, deleted (undo puts them back).

Array<string>
archived
required

Rows of a dropped table moved to its archive folder.

Array<object>
object
from
required
string
to
required
string
unchanged
required

Logged tables already as they were then (no new version).

Array<string>
skipped
required

Tables that cannot be rewound (no transaction log, or not that far back), with the reason.

Array<object>
object
table
required
string
reason
required
string

Example

{
"violations": [
{
"violations": [
{
"code": "required"
}
]
}
],
"ambiguous_mentions": [
{
"reason": "same_name"
}
],
"tables": [
{
"action": "restore"
}
]
}

Bad input: the body is not a JSON object, or an argument is unknown, missing or of the wrong type.

Media typeapplication/json
object
error
required

What went wrong, for a person or an agent.

string

Example generated

{
"error": "example"
}

Missing or wrong bearer token.

Media typeapplication/json
object
error
required

What went wrong, for a person or an agent.

string

Example generated

{
"error": "example"
}

A named token beyond its permissions (the engine’s administration, tables outside its write patterns, schema changes without ddl).

Media typeapplication/json
object
error
required

What went wrong, for a person or an agent.

string

Example generated

{
"error": "example"
}

Refused (validation failures, conflicts, an unmet expect): nothing written. Same body as 200, with ok: false and the reasons.

Media typeapplication/json
RestoreDatabaseResult

Result of restore_database: a write operation’s result plus what it does to each table. A refusal (ok false) is answered with HTTP 422, a failed write with 500, so a 2xx body has ok true.

object
ok
required

True when the operation was applied (or, on a dry run, would be).

boolean
op
required

The operation, by the name it was called with (e.g. insert_row, create_table, recompute_columns).

string
dry_run
required

True when nothing was written (preview).

boolean
migration_id

Journal id of the applied operation: pass it to undo_migration. Absent on a dry run.

string
notes_changed
required

Notes whose front matter or body were written.

integer
files_created
required

Files created.

integer
files_moved
required

Files moved or renamed.

integer
files_deleted
required

Files deleted or archived.

integer
references_updated
required

Links rewritten in other notes.

integer
conflicts
required

Reasons the operation was refused (empty on success).

Array<object>
object
path
required

Note or file path.

string
message
required

Why the operation cannot proceed.

string
violations
required

Rows that would break the table’s rules (empty on success).

Array<object>
RowViolations

The violations of one row.

object
path
required

Row note path.

string
violations
required

What is wrong with this row.

Array<object>
Violation
object
column

The column the violation is about (every code but check and unreadable).

string
index

The item of a list column that breaks the rule, from 0.

integer
constraint

The CHECK’s name (code check).

string
code
required

Kind of violation.

string
Allowed values: required inverse type min max step enum broken_link ref unique unknown_column check generated cycle vocabulary unreadable
message
required

Agent-readable explanation.

string
value

The offending value, when there is one.

failed
required

Files that could not be written (empty on success).

Array<object>
object
path
required

Vault path.

string
error
required

What went wrong.

string
rolled_back

Set when a write failed partway (failed): true when the engine put back what it had written, so nothing is left written; false when that rollback failed too (failed names the files left, and undo_migration on migration_id retries it).

boolean
planned_edits
required

Front matter edits per note (planned, or made).

Array<object>
object
path
required

Note path.

string
set
required

Front matter keys set, with their new values.

object
key
additional properties
any
remove
required

Front matter keys removed.

Array<string>
body

True when the note body changes too.

boolean
planned_creates
required

Paths of notes created.

Array<string>
planned_moves
required

Files moved: from → to.

Array<object>
object
from
required
string
to
required
string
planned_deletes
required

Paths deleted (or archived).

Array<string>
planned_texts
required

Files rewritten whole, e.g. metastore.yaml for DDL.

Array<string>
commits

Transaction-log commits written (tables with history on).

Array<object>
object
table
required

Qualified table.

string
version
required

New log version.

integer
operation
required

Log operation, e.g. WRITE.

string
links_added

Links the write added to the text it wrote: the notes the text mentions by name (automatic links). Present when there is one.

Array<object>
LinkAdded

A link the write added in place of a mention.

object
path
required

The note the link was written into.

string
text
required

The mention, as written.

string
target
required

Vault path of the note it links.

string
link
required

The link written in place of the mention.

string
ambiguous_mentions

Mentions left as text because the engine is not sure which note they name. Present when there is one: read the candidates and the context, then link the right one with update_row and autolink: false, or leave the text.

Array<object>
LinkAmbiguous

A mention left as text: more than one note could be meant.

object
path
required

The note the mention is in.

string
text
required

The mention, as written.

string
reason
required

Same_name: several notes have this name; adjacent: names of different notes side by side, which may be one name; overlap: names of notes overlap; part_of_name: a capitalized word next to it suggests a longer name; sentence_start: a one-word name at the start of a sentence, a line, a list item or a label, where its capital says nothing.

string
Allowed values: same_name adjacent overlap part_of_name sentence_start
candidates
required

Vault paths of the notes it may name.

Array<string>
context
required

The line around the mention.

string
hint
required

What to do: read the candidates, then link the right one with update_row and autolink: false, or leave the text.

string
restored_to
required

The moment restored (ISO date-time): timestamp, or the last millisecond before the first commit of before_migration; given back as timestamp, it names the same state.

string
tables
required

The tables that change.

Array<object>
object
table
required

Qualified table.

string
action
required

Restore: rows and/or definition go back; drop: the table did not exist then (definition removed, rows archived); recreate: dropped since, it comes back.

string
Allowed values: restore drop recreate
version
required
Any of:
integer
definition_changed
required

Its entry in metastore.yaml changes.

boolean
creates
required

Rows re-created.

Array<string>
texts
required

Rows that get their old text back.

Array<string>
deletes
required

Rows created since, deleted (undo puts them back).

Array<string>
archived
required

Rows of a dropped table moved to its archive folder.

Array<object>
object
from
required
string
to
required
string
unchanged
required

Logged tables already as they were then (no new version).

Array<string>
skipped
required

Tables that cannot be rewound (no transaction log, or not that far back), with the reason.

Array<object>
object
table
required
string
reason
required
string

Example

{
"violations": [
{
"violations": [
{
"code": "required"
}
]
}
],
"ambiguous_mentions": [
{
"reason": "same_name"
}
],
"tables": [
{
"action": "restore"
}
]
}

Unexpected error ({error}), or a write that failed partway and could not be rolled back: rolled_back: false, failed lists the files left (undo_migration on migration_id retries the rollback).

Media typeapplication/json
Any of:
RestoreDatabaseResult

Result of restore_database: a write operation’s result plus what it does to each table. A refusal (ok false) is answered with HTTP 422, a failed write with 500, so a 2xx body has ok true.

object
ok
required

True when the operation was applied (or, on a dry run, would be).

boolean
op
required

The operation, by the name it was called with (e.g. insert_row, create_table, recompute_columns).

string
dry_run
required

True when nothing was written (preview).

boolean
migration_id

Journal id of the applied operation: pass it to undo_migration. Absent on a dry run.

string
notes_changed
required

Notes whose front matter or body were written.

integer
files_created
required

Files created.

integer
files_moved
required

Files moved or renamed.

integer
files_deleted
required

Files deleted or archived.

integer
references_updated
required

Links rewritten in other notes.

integer
conflicts
required

Reasons the operation was refused (empty on success).

Array<object>
object
path
required

Note or file path.

string
message
required

Why the operation cannot proceed.

string
violations
required

Rows that would break the table’s rules (empty on success).

Array<object>
RowViolations

The violations of one row.

object
path
required

Row note path.

string
violations
required

What is wrong with this row.

Array<object>
Violation
object
column

The column the violation is about (every code but check and unreadable).

string
index

The item of a list column that breaks the rule, from 0.

integer
constraint

The CHECK’s name (code check).

string
code
required

Kind of violation.

string
Allowed values: required inverse type min max step enum broken_link ref unique unknown_column check generated cycle vocabulary unreadable
message
required

Agent-readable explanation.

string
value

The offending value, when there is one.

failed
required

Files that could not be written (empty on success).

Array<object>
object
path
required

Vault path.

string
error
required

What went wrong.

string
rolled_back

Set when a write failed partway (failed): true when the engine put back what it had written, so nothing is left written; false when that rollback failed too (failed names the files left, and undo_migration on migration_id retries it).

boolean
planned_edits
required

Front matter edits per note (planned, or made).

Array<object>
object
path
required

Note path.

string
set
required

Front matter keys set, with their new values.

object
key
additional properties
any
remove
required

Front matter keys removed.

Array<string>
body

True when the note body changes too.

boolean
planned_creates
required

Paths of notes created.

Array<string>
planned_moves
required

Files moved: from → to.

Array<object>
object
from
required
string
to
required
string
planned_deletes
required

Paths deleted (or archived).

Array<string>
planned_texts
required

Files rewritten whole, e.g. metastore.yaml for DDL.

Array<string>
commits

Transaction-log commits written (tables with history on).

Array<object>
object
table
required

Qualified table.

string
version
required

New log version.

integer
operation
required

Log operation, e.g. WRITE.

string
links_added

Links the write added to the text it wrote: the notes the text mentions by name (automatic links). Present when there is one.

Array<object>
LinkAdded

A link the write added in place of a mention.

object
path
required

The note the link was written into.

string
text
required

The mention, as written.

string
target
required

Vault path of the note it links.

string
link
required

The link written in place of the mention.

string
ambiguous_mentions

Mentions left as text because the engine is not sure which note they name. Present when there is one: read the candidates and the context, then link the right one with update_row and autolink: false, or leave the text.

Array<object>
LinkAmbiguous

A mention left as text: more than one note could be meant.

object
path
required

The note the mention is in.

string
text
required

The mention, as written.

string
reason
required

Same_name: several notes have this name; adjacent: names of different notes side by side, which may be one name; overlap: names of notes overlap; part_of_name: a capitalized word next to it suggests a longer name; sentence_start: a one-word name at the start of a sentence, a line, a list item or a label, where its capital says nothing.

string
Allowed values: same_name adjacent overlap part_of_name sentence_start
candidates
required

Vault paths of the notes it may name.

Array<string>
context
required

The line around the mention.

string
hint
required

What to do: read the candidates, then link the right one with update_row and autolink: false, or leave the text.

string
restored_to
required

The moment restored (ISO date-time): timestamp, or the last millisecond before the first commit of before_migration; given back as timestamp, it names the same state.

string
tables
required

The tables that change.

Array<object>
object
table
required

Qualified table.

string
action
required

Restore: rows and/or definition go back; drop: the table did not exist then (definition removed, rows archived); recreate: dropped since, it comes back.

string
Allowed values: restore drop recreate
version
required
Any of:
integer
definition_changed
required

Its entry in metastore.yaml changes.

boolean
creates
required

Rows re-created.

Array<string>
texts
required

Rows that get their old text back.

Array<string>
deletes
required

Rows created since, deleted (undo puts them back).

Array<string>
archived
required

Rows of a dropped table moved to its archive folder.

Array<object>
object
from
required
string
to
required
string
unchanged
required

Logged tables already as they were then (no new version).

Array<string>
skipped
required

Tables that cannot be rewound (no transaction log, or not that far back), with the reason.

Array<object>
object
table
required
string
reason
required
string

Example

{
"violations": [
{
"violations": [
{
"code": "required"
}
]
}
],
"ambiguous_mentions": [
{
"reason": "same_name"
}
],
"tables": [
{
"action": "restore"
}
]
}

A write that failed partway (a file another program holds) and was rolled back: rolled_back: true, nothing written. Send it again later. Same body as 200, with ok: false and failed.

Media typeapplication/json
RestoreDatabaseResult

Result of restore_database: a write operation’s result plus what it does to each table. A refusal (ok false) is answered with HTTP 422, a failed write with 500, so a 2xx body has ok true.

object
ok
required

True when the operation was applied (or, on a dry run, would be).

boolean
op
required

The operation, by the name it was called with (e.g. insert_row, create_table, recompute_columns).

string
dry_run
required

True when nothing was written (preview).

boolean
migration_id

Journal id of the applied operation: pass it to undo_migration. Absent on a dry run.

string
notes_changed
required

Notes whose front matter or body were written.

integer
files_created
required

Files created.

integer
files_moved
required

Files moved or renamed.

integer
files_deleted
required

Files deleted or archived.

integer
references_updated
required

Links rewritten in other notes.

integer
conflicts
required

Reasons the operation was refused (empty on success).

Array<object>
object
path
required

Note or file path.

string
message
required

Why the operation cannot proceed.

string
violations
required

Rows that would break the table’s rules (empty on success).

Array<object>
RowViolations

The violations of one row.

object
path
required

Row note path.

string
violations
required

What is wrong with this row.

Array<object>
Violation
object
column

The column the violation is about (every code but check and unreadable).

string
index

The item of a list column that breaks the rule, from 0.

integer
constraint

The CHECK’s name (code check).

string
code
required

Kind of violation.

string
Allowed values: required inverse type min max step enum broken_link ref unique unknown_column check generated cycle vocabulary unreadable
message
required

Agent-readable explanation.

string
value

The offending value, when there is one.

failed
required

Files that could not be written (empty on success).

Array<object>
object
path
required

Vault path.

string
error
required

What went wrong.

string
rolled_back

Set when a write failed partway (failed): true when the engine put back what it had written, so nothing is left written; false when that rollback failed too (failed names the files left, and undo_migration on migration_id retries it).

boolean
planned_edits
required

Front matter edits per note (planned, or made).

Array<object>
object
path
required

Note path.

string
set
required

Front matter keys set, with their new values.

object
key
additional properties
any
remove
required

Front matter keys removed.

Array<string>
body

True when the note body changes too.

boolean
planned_creates
required

Paths of notes created.

Array<string>
planned_moves
required

Files moved: from → to.

Array<object>
object
from
required
string
to
required
string
planned_deletes
required

Paths deleted (or archived).

Array<string>
planned_texts
required

Files rewritten whole, e.g. metastore.yaml for DDL.

Array<string>
commits

Transaction-log commits written (tables with history on).

Array<object>
object
table
required

Qualified table.

string
version
required

New log version.

integer
operation
required

Log operation, e.g. WRITE.

string
links_added

Links the write added to the text it wrote: the notes the text mentions by name (automatic links). Present when there is one.

Array<object>
LinkAdded

A link the write added in place of a mention.

object
path
required

The note the link was written into.

string
text
required

The mention, as written.

string
target
required

Vault path of the note it links.

string
link
required

The link written in place of the mention.

string
ambiguous_mentions

Mentions left as text because the engine is not sure which note they name. Present when there is one: read the candidates and the context, then link the right one with update_row and autolink: false, or leave the text.

Array<object>
LinkAmbiguous

A mention left as text: more than one note could be meant.

object
path
required

The note the mention is in.

string
text
required

The mention, as written.

string
reason
required

Same_name: several notes have this name; adjacent: names of different notes side by side, which may be one name; overlap: names of notes overlap; part_of_name: a capitalized word next to it suggests a longer name; sentence_start: a one-word name at the start of a sentence, a line, a list item or a label, where its capital says nothing.

string
Allowed values: same_name adjacent overlap part_of_name sentence_start
candidates
required

Vault paths of the notes it may name.

Array<string>
context
required

The line around the mention.

string
hint
required

What to do: read the candidates, then link the right one with update_row and autolink: false, or leave the text.

string
restored_to
required

The moment restored (ISO date-time): timestamp, or the last millisecond before the first commit of before_migration; given back as timestamp, it names the same state.

string
tables
required

The tables that change.

Array<object>
object
table
required

Qualified table.

string
action
required

Restore: rows and/or definition go back; drop: the table did not exist then (definition removed, rows archived); recreate: dropped since, it comes back.

string
Allowed values: restore drop recreate
version
required
Any of:
integer
definition_changed
required

Its entry in metastore.yaml changes.

boolean
creates
required

Rows re-created.

Array<string>
texts
required

Rows that get their old text back.

Array<string>
deletes
required

Rows created since, deleted (undo puts them back).

Array<string>
archived
required

Rows of a dropped table moved to its archive folder.

Array<object>
object
from
required
string
to
required
string
unchanged
required

Logged tables already as they were then (no new version).

Array<string>
skipped
required

Tables that cannot be rewound (no transaction log, or not that far back), with the reason.

Array<object>
object
table
required
string
reason
required
string

Example

{
"violations": [
{
"violations": [
{
"code": "required"
}
]
}
],
"ambiguous_mentions": [
{
"reason": "same_name"
}
],
"tables": [
{
"action": "restore"
}
]
}