How to initialize data structure for your new Skygear app


How can we initialize data structure for a new project?

When Skygear saves your records at the cloudDB, it automatically handles the DB schema. Skygear updates the schema behind the scene on the fly upon record save requests.

Quick way to save a record with JavaScript

You can save a record via JS SDK:
For example, we want to set up a Note record with title, content, and rate fields.

<!--Skygear CDN-->
<script src=""></script>
<script src=""></script>

var msg = document.getElementById('msg');

  'endPoint': '', // trailing slash is required
  'apiKey': '4bb9cb48bab7439c97f6d033204841fc', 
}).then(() => {
  console.log('skygear container is now ready for making API calls.');

    var Note = skygear.Record.extend("Note");
    note = new Note({    // Save a template record here
    'title': 'Title', // Define custom fields
    'content': 'Hello World',
    'rate': 1
    msg.innerText = msg.innerText+' Saved note as record (ID: '+result._id+')\n';

}, (error) => {

<span id="msg"><span>

Live example:

Database data importer

Furthermore, to intialize a batch of data, you can also import data from CSV files with this helper script.



Title 1, Good morning!, 1
Title 2, Good night, 3

Then run the following script to import existing notes to as Note record:

skygear-data-importer -e '' -k 'APIKEY_XXXXXXXXXXX' -t 'Note' 'note_records.csv'

Freezing the database schema

When you launch your app publicly, you may want to freeze the database schema to prevent unexpected changes to your cloudDB. You can update the settings at Skygear Portal > Database > Settings > Database Schema Freezing

If you have further questions. Please ask below and let us know :wink: