-
Notifications
You must be signed in to change notification settings - Fork 4
Levure Creating a database
Trevor DeVore edited this page Nov 28, 2018
·
2 revisions
SQL Yoga allows you to create a database from scratch using a YAML file as well.
- Create a
migrate
folder in your./app/database
folder. - Create a file named
001_create_tables.yml
in the./app/database/migrate
folder. - Add the following YAML to the file:
migration:
create tables:
- For each table you want to create add the following:
- name: TABLE_NAME
fields:
- { name: FIELD_NAME, type: FIELD_TYPE }
- Open your Levure application open in the Livecode IDE.
- In the message box call
sqlyogadev_runMigrations;put the result
.
Your database will now have the tables and fields you specified and the ./app/database/schema.yml
file will contain the new schema. If any errors occurred they will be reported in the message box due to the addition of ;put the result
.
SQL Yoga will create a table named schema
with a version
column. The version of the last run migration will be stored in this table. This is how SQL Yoga knows the last migration to run. In this case the value in the version
column will be 1
.
You can also create new records in the migration file.
migration:
create tables:
...
create records:
- table: TABLE_NAME
records:
- { FIELD_NAME: FIELD_VALUE, FIELD_NAME: FIELD_VALUE }
- If you need to modify your database later on create a file named
002_create_tables.yml
in the./app/database/migrate
folder. - Populate the YAML file as described above.
- In the message box call
sqlyogadev_runMigrations;put the result
. Since SQL Yoga stored the migration version number previously it will only process the002_create_tables.yml
file.
SQL Yoga USER GUIDE
- Home
- SQL Yoga Objects
- Database Objects
- Connection Objects
- SQL Query Objects
- SQL Record Objects
- Table Objects
- Table Object Behaviors
- Relationships
- Scopes
- Schema
- Working with User Search Strings
- SQL Query Template Objects
- Error Handling
- Migrating from SQL Yoga 1.x
- Integrating with the Levure Application Framework