new-cluster name=s1 allow-implicit-access
----

# Test that dropping the full backup causes a graceful failure on ALTER.

exec-sql
create schedule datatest for backup into 'nodelocal://1/example-schedule' recurring '@daily' full backup '@weekly';
----

let $fullID $incID
with schedules as (show schedules) select id from schedules where label='datatest' order by command->>'backup_type' asc;
----

query-sql
with schedules as (show schedules) select id, state, recurrence, owner, command from schedules where label='datatest' order by command->>'backup_type' asc;
----
$fullID <nil> @weekly root {"backup_statement": "BACKUP INTO 'nodelocal://1/example-schedule' WITH OPTIONS (detached)", "chain_protected_timestamp_records": true, "dependent_schedule_id": $incID, "unpause_on_success": $incID}
$incID Waiting for initial backup to complete @daily root {"backup_statement": "BACKUP INTO LATEST IN 'nodelocal://1/example-schedule' WITH OPTIONS (detached)", "backup_type": 1, "chain_protected_timestamp_records": true, "dependent_schedule_id": $fullID}

exec-sql
drop schedule $fullID
----

# Test that dropping the incremental backup is not an issue.

exec-sql
create schedule datatest for backup into 'nodelocal://1/example-schedule' recurring '@daily' full backup '@weekly';
----

let $fullID $incID
with schedules as (show schedules) select id from schedules where label='datatest' order by command->>'backup_type' asc;
----

query-sql
with schedules as (show schedules) select id, state, recurrence, owner, command from schedules where label='datatest' order by command->>'backup_type' asc;
----
$fullID <nil> @weekly root {"backup_statement": "BACKUP INTO 'nodelocal://1/example-schedule' WITH OPTIONS (detached)", "chain_protected_timestamp_records": true, "dependent_schedule_id": $incID, "unpause_on_success": $incID}
$incID Waiting for initial backup to complete @daily root {"backup_statement": "BACKUP INTO LATEST IN 'nodelocal://1/example-schedule' WITH OPTIONS (detached)", "backup_type": 1, "chain_protected_timestamp_records": true, "dependent_schedule_id": $fullID}

exec-sql
drop schedule $incID
----

# The schedule remains in a valid state.

query-sql
with schedules as (show schedules) select id, state, recurrence, owner, command from schedules where label='datatest' order by command->>'backup_type' asc;
----
$fullID <nil> @weekly root {"backup_statement": "BACKUP INTO 'nodelocal://1/example-schedule' WITH OPTIONS (detached)", "chain_protected_timestamp_records": true}

exec-sql
alter backup schedule $fullID set recurring '@daily';
----

query-sql
with schedules as (show schedules) select id, state, recurrence, owner, command from schedules where label='datatest' order by command->>'backup_type' asc;
----
$fullID <nil> @daily root {"backup_statement": "BACKUP INTO 'nodelocal://1/example-schedule' WITH OPTIONS (detached)", "chain_protected_timestamp_records": true}
