Skip to content

Commit 04d65d6

Browse files
committed
Simplify database initialization examples with direct SQL execution
1 parent e00c876 commit 04d65d6

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

‎howto/create-database.html‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,21 @@ <h2>MariaDB</h2>
9494
<h2>Initialize it with Scriptella</h2>
9595
<p>If you have not installed Scriptella yet, use the <a href="../download.html#one-command-installer">one-command installer</a>:</p>
9696
<pre><code>curl -fsSL https://scriptella.org/install.sh | sh</code></pre>
97-
<p>Follow the installer's instructions for adding Scriptella to your <code>PATH</code>. If it updates a startup file, start a new shell or reload that file before using <code>scriptella.sh</code>; if it says PATH was not changed automatically, add the printed export line. Download the <a href="https://jdbc.postgresql.org/download/">PostgreSQL pgJDBC driver</a> and place the JAR in <code>${HOME}/.local/scriptella/lib</code>. Save this example as <code>init.etl.xml</code>; it connects to the PostgreSQL database, creates a table, and inserts its first row:</p>
97+
<p>Follow the installer's instructions for adding Scriptella to your <code>PATH</code>. If it updates a startup file, start a new shell or reload that file before using <code>scriptella.sh</code>; if it says PATH was not changed automatically, add the printed export line.</p>
98+
<p>Download the <a href="https://jdbc.postgresql.org/download/">PostgreSQL pgJDBC driver</a> and place the JAR in <code>${HOME}/.local/scriptella/lib</code>. Save this SQL as <code>init.sql</code>:</p>
99+
<pre><code class="language-sql">CREATE TABLE message (
100+
id INTEGER PRIMARY KEY,
101+
text VARCHAR(100)
102+
);
103+
104+
INSERT INTO message VALUES (1, 'Hello from Scriptella');</code></pre>
105+
<p>Run <code>init.sql</code> with Scriptella 1.6 or newer, replacing the username and password with your PostgreSQL credentials:</p>
106+
<pre><code>scriptella.sh execute-sql \
107+
--url jdbc:postgresql://localhost/myapp \
108+
--user YOUR_POSTGRES_USER \
109+
--password YOUR_POSTGRES_PASSWORD \
110+
init.sql</code></pre>
111+
<p>Or save this ETL file as <code>init.etl.xml</code> alongside <code>init.sql</code>:</p>
98112
<pre><code class="language-xml">&lt;!DOCTYPE etl SYSTEM "http://scriptella.org/dtd/etl.dtd"&gt;
99113
&lt;etl&gt;
100114
&lt;connection
@@ -104,18 +118,13 @@ <h2>Initialize it with Scriptella</h2>
104118
password="YOUR_POSTGRES_PASSWORD"/&gt;
105119

106120
&lt;script&gt;
107-
CREATE TABLE message (
108-
id INTEGER PRIMARY KEY,
109-
text VARCHAR(100)
110-
);
111-
112-
INSERT INTO message VALUES (1, 'Hello from Scriptella');
121+
&lt;include href="init.sql"/&gt;
113122
&lt;/script&gt;
114123
&lt;/etl&gt;</code></pre>
115-
<p>Run the ETL file with Scriptella:</p>
124+
<p>Run the ETL file:</p>
116125
<pre><code>scriptella.sh init.etl.xml</code></pre>
117-
<p>This creates the table and inserts the first row. The same approach works with <a href="https://mariadb.com/docs/connectors/mariadb-connector-j/">MariaDB</a> and other JDBC databases by changing the JDBC driver and connection URL.</p>
118-
<p>For larger schemas, SQL can also be kept in separate files and included from the ETL file.</p>
126+
<p>This creates the table and inserts the first row. See <a href="../reference/index.html#direct-sql">direct SQL execution</a> for command options, or the <a href="../tutorial.html">tutorial</a> for more ETL examples.</p>
127+
<p>The same approach works with <a href="https://mariadb.com/docs/connectors/mariadb-connector-j/">MariaDB</a> and other JDBC databases by installing the appropriate JDBC driver and changing the connection URL. For MariaDB, use <code>jdbc:mariadb://localhost/myapp</code>.</p>
119128
</section>
120129

121130
<section id="whats-next">

0 commit comments

Comments
 (0)