Back

[SOLVED] Is there a way to automate setting up an Appwrite cloud database?

  • 0
  • Databases
saricden
1 Jun, 2023, 20:42

Is it possible to automate or provide a template to setup a new Appwrite cloud database for a user?

Things I would need to automate or template include:

  • Creating a DB
  • Creating collections with specific attributes in that DB

Thanks! πŸ™‚

TL;DR
Yes, there is a way to automate setting up an Appwrite cloud database. You can use the database Server SDK and create a migration script. Here is an example in JavaScript: 1. Initialize the SDK and client: ```js const sdk = require('node-appwrite'); const client = new sdk.Client(); const databases = new sdk.Databases(client); ``` 2. Set the endpoint, project ID, and API key: ```js client .setEndpoint('https://cloud.appwrite.io/v1') .setProject('5df5acd0d48c2') .setKey('919c
Binyamin
1 Jun, 2023, 20:48

Yes You'll need to use the database Server SDK, and then create your migration script Something like this for example:

TypeScript
const sdk = require('node-appwrite');

// Init SDK
const client = new sdk.Client();

const databases = new sdk.Databases(client);

client
    .setEndpoint('https://cloud.appwrite.io/v1')
    .setProject('5df5acd0d48c2')
    .setKey('919c2d18fb5d4...a2ae413da83346ad2');

// Create Database
await databases.create('[DATABASE_ID]', '[NAME]');

// Create collection
await databases.createCollection('[DATABASE_ID]', '[COLLECTION_ID]', '[NAME]');


// Create string attribute
await databases.createStringAttribute('[DATABASE_ID]', '[COLLECTION_ID]', 'username', 1, false);

// Add index
await databases.createIndex('[DATABASE_ID]', '[COLLECTION_ID]', 'user', 'key', ['username']);
Binyamin
1 Jun, 2023, 20:48

Take a look at the Server SDK here https://appwrite.io/docs/server/databases

saricden
1 Jun, 2023, 20:49

Woohoo!!! Thank you so much @Binyamin this means my idea for the Hackathon is very possible

Drake
1 Jun, 2023, 21:23

[SOLVED] Is there a way to automate setting up an Appwrite cloud database?

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more