6.3 Quick Start
This section introduces the SQLcl Projects feature using a simple setup and list of tasks. The quick start covers:
- How to initialize a new project (for an application with a
single schema called
demo) . - Work to be done as part of a sprint:
- Ticket-1
- Create the standard sample
deptandemptables - Load the tables with sample data
- Create the standard sample
- Ticket-2
- Add a new column named
emailto theemptable - Add a new function named get_display_name
- Add a new column named
- Ticket-1
- How to complete a release, and then generate and deploy an artifact.
Topics
6.3.1 Prerequisites
This Quick Start has the following prerequisites:
- You must create two databases,
DEVandPROD, with thedemoschema pre-created. You need to connect as thedemouser from SQLcl.create user demo identified by demo; grant resource to demo; grant connect to demo; grant create view to demo; alter user demo quota unlimited on system; - You require two named connections in SQLcl:
demo-devanddemo-prod. The following examples show how to add and manage named connections in SQLcl.-Add a new named connection -Note: -savepwd is an optional parameter to save the password. SQL> conn -savepwd -save demo-dev demo/demo@//myserver.com:1521/mypdb -List current connections SQL> connmgr list -To connect to a named connection SQL> conn -name demo-dev
6.3.2 Assumptions
This quick start assumes the following:
- A Git project named
demo-projectis used.All work in the repository is "local" only, a remote server (such as, Github or Gitlab) is not needed for this demo.
- The term ticket (or issue) refers to a unit of work, typically tracked in a system such as Jira.
- SQLcl can run operating system level commands using the
hostcommand.- For example,
host dateprints the system date. - A shortcut for the host command is
!<cmd>. For example,!dateis the equivalent ofhost date. - This demo uses a lot of
hostcommands. To avoid exiting and entering SQLcl each time, the!shortcut is used to execute them directly within SQLcl.
- For example,
6.3.3 Project Setup
Create a Git repository.
Note:
This demo uses a local Git repository. In most cases, a clone from a remote Git repository is used as a starting point.-Create and go into new folder
mkdir demo-project
cd demo-project
-Start SQLcl
sql /nolog
-Initialize git repo
SQL> !git init --initial-branch=main
Initialize the repository for SQLcl Projects.
-The schema that is used for this demo is called "demo".
SQL> project init -name demo_project -schemas demo
------------------------
PROJECT DETAILS
------------------------
Project name: demo_project
Schema(s): DEMO
Directory: /private/tmp/demo-project
Connection name:
Project root: demo-project
Your project has been successfully created
-Root folder now looks like:
- .
- ├── .dbtools
- │ ├── filters
- │ │ └── project.filters
- │ ├── project.config.json
- │ └── project.sqlformat.xml
- ├── dist
- │ └── install.sql
- └── src
- │ └── database
- ├── .gitignore
- └── README.md
-Add and commit the initial files to the repository
SQL> !git add --all
SQL> !git commit -m "initial"
[main (root-commit) 5fa6ebd] initial
9 files changed, 188 insertions(+)
create mode 100644 .dbtools/filters/project.filters
create mode 100644 .dbtools/project.config.json
create mode 100644 .dbtools/project.sqlformat.xml
create mode 100644 .gitignore
create mode 100644 README.md
create mode 100644 dist/install.sql
6.3.4 Ticket-1
In practice, most development is done as part of a ticket in a project
management system, such as Jira or GitHub. In this section,
ticket-1 is created and has the following requirements:
- Create
empanddepttables. - Add the initial data.
In the following steps, you will:
-
Create and check out a Git branch named
ticket-1. -
Create the tables in the database schema.
-
Export the objects from the schema to the project's
srcfolder. -
Register the changes in the project's
distfolder.- Changes are detected automatically by comparing the feature branch to the main branch.
- Changes are created in the next release as part of
ticket-1. - Changes are captured as Liquibase changelogs/sets.
-
Add a custom script to load the initial data for the
empanddepttables. - Commit and merge changes to complete the ticket.
Steps
6.3.5 Ticket-2
Now that the first ticket is complete, work can start on
TICKET-2. The purpose of this ticket is to highlight the
automated DDL management along with soft objects (that is, re-runnable objects such
as packages, views, and so on) creation.
TICKET-2 has the following requirements:
- Add a new column
emp.email. - Add a new function
get_display_name.
The steps are:
- Create and check out a Git branch called
ticket-2. - Alter the
emptable and add the new column in the database. - Export the
emptable. This will show the new table structure in thesrc/.../tables/emp.sqlfile. - Run the
project stagecommand to register the alter table statements. - Create a new function,
get_display_name, in the database and runproject export. - Rerun the
project stagecommand to include theget_display_namefunction. - Commit and merge changes to complete the ticket.
Steps
6.3.6 Final Steps
After the sprint is complete, the following needs to be done:
- Generate a release (
project release)- The
releasecommand renames thedist/nextfolder to the release name (in the following example, 1.0.0 ) and then generates a new (empty)dist/next folderready for the next sprint's changes.
- The
- Generate an artifact (
project gen-artifact)gen-artifactcreates a zip file that contains a single install.sql file, which points to all the different sub-folders in thedistfolder. In this example, it only contains one folder (1.0.0). Over time, the artifact will contain additional releases, as this is what allows Liquibase to upgrade from any point in time.
- Deploy the artifact (
project deploy).- The
deploycommand takes an artifact and upgrades an environment to the latest version. For example, if the artifact includes versions 1-10 and the current environment is on version 8, the installer auto-detects the current state and only runs the changes related to version 9 and version 10.
- The
6.3.6.1 Generate Release 1.0.0
- Moves the contents of
dist/nextto the name of the release. For example, if generating release 1.0.0, then dist/next > dist/1.0.0. - Create a new
dist/nextfolder that is open for the next set of work for the next release.
6.3.6.2 Generate an Artifact
An artifact contains all the releases that enable the deployment to automatically detect the instance's current version and the required releases to run through to update to the latest. SQLcl generates the artifact as a zipped file. By default, this file is not included in the Git repository because it is a binary file that can become large over time.
Note:
Artifacts must be stored in an artifact repository such as JFrog's Artifactory.Generate the artifact as follows:
SQL> project gen-artifact -version 1.0.0
Your artifact has been generated demo_project-1.0.0.zip
The artifact directory now contains the following artifact:
├── artifact
│ └── demo_project-1.0.0.zip
By default, the artifact directory is included in the .gitignore file and not added to the repository. It is best practice to move these to an artifact repository (for example, JFrog).