Exporting data model via CLI (Unable due to read access only)
-
Hi,
Currently the only method to export the data model structure in Directus is through the CLI. However, due to read access limitation in Cloudron, this is not working.
Reference: https://www.restack.io/docs/directus-knowledge-directus-export-schema-guide
So how I can export it then?
Thanks
-
I have been able to find a turnaround for exporting the schema using Node.js.
===========
To export your schema from a Directus instance using Node.jsPrerequisites
- Node.js Installed: Ensure Node.js is installed on your system.
- Directus Instance and Token: Obtain your source Directus project URL and access token.
Steps to Export the Schema
-
Setup Node.js Project:
- Create a new directory and initialize a Node.js project:
mkdir directus-schema-export cd directus-schema-export npm init -y - Install the required package:
npm install cross-fetch
- Create a new directory and initialize a Node.js project:
-
Create the Script:
-
Create a file, e.g.,
export-schema.js, and add the following code:const fetch = require('cross-fetch'); // Replace with your actual Directus project URL and access token const SOURCE_URL = 'https://your-directus-instance.com'; // Your Directus URL const SOURCE_TOKEN = 'your-access-token'; // Your Directus access token async function exportSchema() { try { const response = await fetch(`${SOURCE_URL}/schema/snapshot?access_token=${SOURCE_TOKEN}`); if (!response.ok) { throw new Error(`Failed to fetch schema: ${response.statusText}`); } const { data } = await response.json(); console.log('Schema exported successfully:', data); return data; } catch (error) { console.error('Error exporting schema:', error.message); } } // Call the function exportSchema();
-
-
Run the Script:
- Execute the script using Node.js:
node export-schema.js - The schema will be logged to the console. You can redirect it to a file:
node export-schema.js > schema.json
- Execute the script using Node.js:
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login