How would I do the following in Next JS App Router and Next Server Actions?
To set up a per-tenant structure in a TypeScript + NextJS App Router application code using Turso, you won't directly manipulate databases through the CLI as your primary means. Instead, you'll interact with the Turso Platform API for operations such as creating the parent (schema) database and child databases. You'll then use the Client SDK to interact with these databases from your application.
Step 1: Create Parent Database (Schema)
This step involves creating a schema database using the Platform API. You'll need to make a POST request to create the parent database with the is_schema field set to true.
// POST request to create the parent (schema) database
fetch('https://api.turso.tech/v1/organizations/{organizationName}/databases', {
method: 'POST',
headers: {
'Authorization': Bearer YOUR_API_TOKEN,
'Content-Type': 'application/json'
},
body: JSON.stringify({
"name": "parent-db",
"group": "default",
"is_schema": true
})
});