Schemas
A schema is a named namespace inside your GC2 (Geo Compute Cloud) database that groups tables, views and sequences. Within one schema two tables cannot share a name, but the same table name can be reused in different schemas; schema1.inductees and schema2.inductees are distinct tables.
In GC2 the schema is also the unit of ownership and addressing. Every sub-user owns a schema named after itself, and several APIs are schema-qualified: the SQL API and GraphQL resolve unqualified table names within a schema, and the OGC services expose one endpoint per schema. The Schema API below creates, lists, renames and deletes schemas, and a new schema can be created together with nested table definitions in a single request.
Add schema
A new schema object can be empty (name is the only property) or contain nested tables.
- Web App
- HTTP
- CLI
POST https://api.gc2.io/api/v4/schemas HTTP/1.1
Content-Type: application/json
Authorization: Bearer abc123
{
"name": "rockhall"
}
gc2 schema add "rockhall"
Get schema
You can either get a single schema or a collection of schemas. The schema object contains all nested object like
tables, columns, indices and constraints. Use the namesOnly parameter to omit nested objects.
- Web App
- HTTP
- CLI
GET https://api.gc2.io/api/v4/schemas?namesOnly HTTP/1.1
Accept: application/json; charset=utf-8
Authorization: Bearer abc123
GET https://api.gc2.io/api/v4/schemas/rockhall,anotherschema HTTP/1.1
Accept: application/json; charset=utf-8
Authorization: Bearer abc123
gc2 schema get "rockhall,anotherschema"
A schema object with nested objects looks like this.
{
"name": "rockhall",
"tables": [
{
"name": "inductees",
"columns": [
{
"name": "id",
"type": "integer",
"is_nullable": false,
"default_value": null,
"comment": null,
"_num": 1,
"_full_type": "integer",
"_typname": "int4",
"_is_array": false,
"_character_maximum_length": null,
"_numeric_precision": 32,
"_numeric_scale": 0,
"_max_bytes": 4,
"_reference": null,
"_restriction": null,
"_is_primary": true,
"_is_unique": true,
"_index_method": [
"btree"
],
"_checks": null
},
{
"name": "name",
"type": "character varying",
"is_nullable": true,
"default_value": null,
"comment": null,
"_num": 2,
"_full_type": "character varying",
"_typname": "varchar",
"_is_array": false,
"_character_maximum_length": -5,
"_numeric_precision": null,
"_numeric_scale": null,
"_max_bytes": 1073741824,
"_reference": null,
"_restriction": null,
"_is_primary": false,
"_is_unique": false,
"_index_method": null,
"_checks": null
}
],
"indices": [
{
"name": "my-new-table-primary",
"method": "btree",
"unique": true,
"columns": [
"id"
]
}
],
"constraints": [
{
"name": "my-new-table-primary",
"constraint": "primary",
"columns": [
"id"
]
}
],
"comment": null
}
]
}
Rename schema
- Web App
- HTTP
- CLI
PATCH https://api.gc2.io/api/v4/schemas/rockhall HTTP/1.1
Content-Type: application/json
Authorization: Bearer abc123
{
"name": "rock_roll_of_hall"
}
gc2 schema rename "rockhall" "myschema2"
Delete schema
Be careful when deleting schemas - all nested objects will also be deleted!
- Web App
- HTTP
- CLI
DELETE https://api.gc2.io/api/v4/schemas/rock_roll_of_hall HTTP/1.1
Authorization: Bearer abc123
gc2 schema drop "rock_roll_of_hall"