The Apprite CLI allows you to create and deploy databases, collections, buckets, teams and functions to your Appwrite project from a configuration file. This is especially helpful if you're trying to track project setup using version control.
After you're logged in, the CLI needs to be initialized with your Appwrite project. You can initialize the CLI using:
appwrite init project
The following prompts will guide you through the setup process. The init command also creates an appwrite.json file representing your Appwrite project.
You can fetch all the existing databases and collections in your current project using:
appwrite init collection
You can fetch all the existing teams in your current project using:
appwrite init team
The CLI also handles the creation and deployment of Appwrite Functions. Run this command in the folder holding your appwrite.json file.
appwrite init function ? What would you like to name your function? My Awesome Function ? What runtime would you like to use? Node.js (node-15.5) ✓ Success
This command creates a new function My Awesome Function in your current Appwrite project and also creates a template function for you to get started.
You can now deploy this function by running this command in the folder holding your appwrite.json file.
appwrite deploy function ? Which functions would you like to deploy? Awesome Function (621229798628cf5bf712) ℹ Info Deploying function Awesome Function ( 621229798628cf5bf712 ) ✓ Success Deployed Awesome Function ( 621229798628cf5bf712 )
The Appwrite CLI also helps you deploy your project's databases and collections schema from one project to another.
You can deploy all the databases and collections in your appwrite.json file by running this command in the folder holding your appwrite.json file.
The deploy command will overwrite existing collections causing existing data to be lost. If you already have data in your project, you will need to write your own migration script using a Server SDK instead of using the CLI.
appwrite deploy collection
The Appwrite CLI can create teams to organize users. Teams can be used to grant access permissions to a group of users. Learn more about permissions.
Deploy teams by running this command in the folder holding your appwrite.json file.
appwrite deploy team
The Appwrite CLI allows you to configure and deploy buckets across projects. All the bucket's settings are available through the appwrite.json file.
Deploy storage buckets by running this command in the folder holding your appwrite.json file.
appwrite deploy bucket
When using appwrite.json, changes made in the Appwrite Console can cause conflicts with the local config. To avoid conflicts, prefer updating configuration locally and deploying instead of using the Console.
The appwrite.json file
An appwrite.json file is created by the CLI when you initialize your project. It stores all the configuration for the CLI to be able to interact with your Appwrite project in JSON format. When using the appwrite deploy command, the CLI uses information from appwrite.json to deploy your functions and collections.
Here's a complete list of all configurable options in appwrite.json:
|projectId||string||ID of your Appwrite Project.|
|projectName||string||Name of your Appwrite Project.|
|functions||array of functions||Configuration of functions in your project.|
|databases||array of databases||Configuration of databases in your project.|
|collections||array of collections||Configuration of collections in your project.|
|teams||array of teams||Configuration of teams in your project.|
|buckets||array of buckets||Configuration of teams in your project.|
|runtime||string||Function runtime, must be enabled. Learn more about runtimes.|
|path||string||Path to folder containing the function's source code.|
|entrypoint||string||Entry point of the function relative to the folder specified in path.|
|ignore||array of strings||Files to ignore inside the function. Learn more about ignoring files.|
|execute||array of strings||Grants execute permissions to users. Learn more about role strings.|
|events||array of strings||Events that trigger the function to execute. Learn more about events.|
|schedule||string||Execute schedule for the function. Learn more about scheduled executions.|
|timeout||int||Execution timeout of the function in seconds, with a maximum configurable limit of 900 seconds.|
|variables||JSON object||Variables provided to the function on execution stored as a key-value JSON object.|
|databaseId||string||ID of the database to which this collection belongs.|
|enabled||bool||If the collection is enabled.|
|documentSecurity||bool||If access permissions can be defined at the document level.|
|$permissions||array of strings||Grants access permissions to users at the collection level. Learn more about permissions.|
|attributes||array of objects||Defines a list of attributes in the collection. Learn more about the Attributes List Object.|
|indexes||array of objects||Defines a list of indexes in the collection. Learn more about the Indexes List Object.|
|$permissions||array of strings||Grants access permissions to users at the bucket level. Learn more about permissions.|
|fileSecurity||boolean||Whether file-level security is enabled. Learn more about permissions.|
|enabled||boolean||Whether the bucket is enabled or disabled.|
|maximumFileSize||integer||Maximum file size supported.|
|allowedFileExtensions||string||List of allowed file extensions.|
|compression||string||Preferred algorithm for compression. Will be one of none, gzip, or zstd.|
|encryption||boolean||Whether the bucket's content is encrypted.|
|antivirus||boolean||Whether virus scanning is enabled for the bucket's content.|