Cloudron makes it easy to run web apps like WordPress, Nextcloud, GitLab on your server. Find out more or install now.


Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Bookmarks
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

Cloudron Forum

Apps | Demo | Docs | Install
  1. Cloudron Forum
  2. Directus
  3. Exporting data model via CLI (Unable due to read access only)

Exporting data model via CLI (Unable due to read access only)

Scheduled Pinned Locked Moved Directus
2 Posts 1 Posters 156 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • I Offline
      I Offline
      igaudette
      wrote on last edited by
      #1

      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

      1 Reply Last reply
      0
      • I Offline
        I Offline
        igaudette
        wrote on last edited by
        #2

        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.js

        Prerequisites

        • 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

        1. 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
            
        2. 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();
            
        3. 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
            
        1 Reply Last reply
        1
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Bookmarks
          • Search