Skip to content
This page View Markdown Open in ChatGPT Open in Claude

Drop indexes

Drops one or more indexes of a table by name, on any database, and reports what happened to each one. A name the table does not have is NOT_FOUND, not an error.

Method POST
URL /api/system-api/admin/drop-indexes : admin is the user path of your account
Body { instance, database, collection | table, indexes: [ names ], ifExists?, continueOnError? } or an array of them
Answer data : one result per name
From code g.sys.system.dropIndexes

The call

Body
{
    "instance": "mysql8", "database": "inventory", "table": "orders",
    "indexes": [ "am_ix_orders_customer_id_status_3f9a1c", "old_idx_status" ],
    "ifExists": true,
    "continueOnError": true
}
Property Required Meaning
instance yes Instance name, crm::acme for a tenant of a multi-tenant instance.
database yes Database name, as the account sees it.
collection or table yes The table.
indexes yes The names to drop.
ifExists no, true A name the table does not have is NOT_FOUND. false : it is FAILED.
continueOnError no, true A drop the database refuses is FAILED and the next ones go on. false : the call fails at the first one.

The answer

{
    "success": true,
    "statusCode": 200,
    "data": [
        { "instance": "mysql8", "database": "inventory", "collection": "orders", "name": "am_ix_orders_customer_id_status_3f9a1c", "fields": [ "customer_id", "status" ], "status": "DROPPED" },
        { "instance": "mysql8", "database": "inventory", "collection": "orders", "name": "old_idx_status", "fields": [], "status": "NOT_FOUND", "message": "The index \"old_idx_status\" does not exist." }
    ]
}
  • The fields of a dropped index are the ones it had. Every drop is logged in the index logs of Index Maker with its source.

From code

g.sys.system.dropIndexes makes the same call from your code, whatever the settings of this API say about HTTP callers.

Drop indexes

Indexes are dropped by name. A name the table does not have is NOT_FOUND, not an error, so the call can run again.

const results = await g.sys.system.dropIndexes({
    instance: 'mysql8',
    database: 'inventory',
    table: 'orders',
    indexes: ['am_ix_orders_customer_id_status_3f9a1c', 'old_idx_status'],
    ifExists: true,         // default : a missing index is NOT_FOUND
    continueOnError: true,  // default : one refused drop does not stop the others
});
// results[0] : { status: 'DROPPED', fields: ['customer_id', 'status'], ... }
// results[1] : { status: 'NOT_FOUND', message: 'The index "old_idx_status" does not exist.', ... }
results = await g.sys.system.drop_indexes(
    'mysql8',
    'inventory',
    table='orders',
    indexes=['am_ix_orders_customer_id_status_3f9a1c', 'old_idx_status'],
    if_exists=True,  # default : a missing index is NOT_FOUND
    continue_on_error=True,  # default : one refused drop does not stop the others
)
# results[0] : { status: 'DROPPED', fields: ['customer_id', 'status'], ... }
# results[1] : { status: 'NOT_FOUND', message: 'The index "old_idx_status" does not exist.', ... }
$results = $g->sys->system->dropIndexes(
    'mysql8',
    'inventory',
    table: 'orders',
    indexes: ['am_ix_orders_customer_id_status_3f9a1c', 'old_idx_status'],
    ifExists: true, // default : a missing index is NOT_FOUND
    continueOnError: true, // default : one refused drop does not stop the others
);
// results[0] : { status: 'DROPPED', fields: ['customer_id', 'status'], ... }
// results[1] : { status: 'NOT_FOUND', message: 'The index "old_idx_status" does not exist.', ... }
var results = await g.Sys.System.DropIndexes(new DropIndexes
{
    Instance = "mysql8",
    Database = "inventory",
    Table = "orders",
    Indexes = ["am_ix_orders_customer_id_status_3f9a1c", "old_idx_status"],
    IfExists = true, // default : a missing index is NOT_FOUND
    ContinueOnError = true, // default : one refused drop does not stop the others
});
// results[0] : { status: 'DROPPED', fields: ['customer_id', 'status'], ... }
// results[1] : { status: 'NOT_FOUND', message: 'The index "old_idx_status" does not exist.', ... }
results, err := g.Sys.System.DropIndexes(am.DropIndexes{
    Instance:        "mysql8",
    Database:        "inventory",
    Table:           "orders",
    Indexes:         []string{"am_ix_orders_customer_id_status_3f9a1c", "old_idx_status"},
    IfExists:        am.Ptr(true), // default : a missing index is NOT_FOUND
    ContinueOnError: am.Ptr(true), // default : one refused drop does not stop the others
})
if err != nil {
    return nil, err
}
// results[0] : { status: 'DROPPED', fields: ['customer_id', 'status'], ... }
// results[1] : { status: 'NOT_FOUND', message: 'The index "old_idx_status" does not exist.', ... }
let results = g.sys.system.drop_indexes(
    DropIndexes::default()
        .instance("mysql8")
        .database("inventory")
        .table("orders")
        .indexes(["am_ix_orders_customer_id_status_3f9a1c", "old_idx_status"])
        .if_exists(true) // default : a missing index is NOT_FOUND
        .continue_on_error(true), // default : one refused drop does not stop the others
)?;
// results[0] : { status: 'DROPPED', fields: ['customer_id', 'status'], ... }
// results[1] : { status: 'NOT_FOUND', message: 'The index "old_idx_status" does not exist.', ... }
1
2
3
4
5
6
7
8
9
var results = g.sys.system.dropIndexes(new DropIndexes()
    .instance("mysql8")
    .database("inventory")
    .table("orders")
    .indexes("am_ix_orders_customer_id_status_3f9a1c", "old_idx_status")
    .ifExists(true) // default : a missing index is NOT_FOUND
    .continueOnError(true)); // default : one refused drop does not stop the others
// results[0] : { status: 'DROPPED', fields: ['customer_id', 'status'], ... }
// results[1] : { status: 'NOT_FOUND', message: 'The index "old_idx_status" does not exist.', ... }
val results = g.sys.system.dropIndexes(
    DropIndexes()
        .instance("mysql8")
        .database("inventory")
        .table("orders")
        .indexes("am_ix_orders_customer_id_status_3f9a1c", "old_idx_status")
        .ifExists(true) // default : a missing index is NOT_FOUND
        .continueOnError(true), // default : one refused drop does not stop the others
)
// results[0] : { status: 'DROPPED', fields: ['customer_id', 'status'], ... }
// results[1] : { status: 'NOT_FOUND', message: 'The index "old_idx_status" does not exist.', ... }

Access, headers and errors

  • Over HTTP, a system API answers only once its settings open it : TOKEN_ACCESS (the token of an API user whose group grants this system API) or IS_PUBLIC. Without settings it is NO_ACCESS : only your code (g.sys) and the admin panel reach it.
  • The settings can also keep the answer in the cache, or ask for the token of a person (authProviders). Pre and post hooks run around it, as around any API.
  • It takes the request headers and answers the envelope. 401 : no valid token, or the API is NO_ACCESS. 403 : no group grants it. 400 : the body is wrong, and the message names the key.

Related : All APIs · System API settings · System APIs from code