Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #8 from electric-sql/without_postgres
Browse files Browse the repository at this point in the history
factoring out postgres creation
  • Loading branch information
paulharter authored Nov 28, 2022
2 parents e92ba97 + abb06d6 commit f0e1631
Show file tree
Hide file tree
Showing 22 changed files with 2,353 additions and 1,118 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ electric-*.tar

# JetBrains project files
.idea/

# Mac thing
.DS_Store
94 changes: 94 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,97 @@ See also https://github.com/bake-bake-bake/bakeware#static-compiling-openssl-int
./dist/electric --help
```


## Migrations command

The `migrations` command lets you create new migrations, build electrified javascript distributions of the migrations
to use in your project, and sync your migrations to our cloud service.

###`migrations init APP_SLUG [--dir MIGRATIONS_DIR]`

Creates a new folder for migrations in your current directory called 'migrations' and adds a new migration
folder to it with a name automatically derived from the current time in UTC and the title `init` e.g. `20221116162204816_init`

Inside this folder will be a file called `migration.sql`. You should write your initial SQLite DDL SQL into this file.

The APP_SLUG you give should be the slug of the app previous created in the web console.
You give it once here and the CLI stores it in the `migrations/manifest.json` so you don't have to keep re-typing it.

The optional `MIGRATIONS_DIR` allows you to create the migration folder somewhere other than the current working directory.

`MIGRATIONS_DIR` must end with the folder name `migrations`


###`migrations app APP_SLUG [--dir MIGRATIONS_DIR]`

Changes the stored `APP_SLUG` that is used by all the other CLI migrations commands.

The optional `MIGRATIONS_DIR` allows you to specify which migration directory to use other than one in the
current working directory.


###`migrations new MIGRATION_TITLE [--dir MIGRATIONS_DIR]`

MIGRATION_TITLE should be a short human readable description of the new migration.

This adds a new migration to the `migrations` folder with a name automatically derived from the current
time in UTC and the given title.

The optional `MIGRATIONS_DIR` allows you to specify which migration directory to use other than one in the
current working directory.


###`migrations build [--dir MIGRATIONS_DIR]`

Builds a javascript file at `dist/index.js` that contains all your migrations with Electric DB's added
DDL and some metadata.

The metadata in this file will have a `"env": "local" to indicate the it was built from your local files
rather that one of the named app environments.

Add this file to your mobile or web project to configure your SQLite database.

The optional `MIGRATIONS_DIR` allows you to specify which migration directory to use other than one in the
current working directory.


###`migrations sync [--env ENVIRONMENT_NAME] [--dir MIGRATIONS_DIR]`

Synchronises changes you have made to migration SQL files in your local `migrations` folder up to the Electric SQl servers,
and builds a new javascript file at `dist/index.js` that matches the newly synchronised set of migrations.

The metadata in this file will have a `"env": ENVIRONMENT_NAME to indicate that it was built directly from and matches
the named app environment.

By default this will sync to the `default` environment for your app. If you want to use a different one give its name
with `--env ENVIRONMENT_NAME`

If the app environment on our servers already has a migration with the same name but different sha256 then this
synchronisation will fail because a migration cannot be modified once it has been applied.
If this happens you have two options, either revert the local changes you have made to the conflicted migration using
the `revert` command below or, if you are working in a development environment that you are happy to reset,
you can reset the whole environment's DB using the web control panel.

Also if a migration has a name that is lower in sort order than one already applied on the server this sync will fail.

The optional `MIGRATIONS_DIR` allows you to specify which migration directory to use other than one in the
current working directory.


###`migrations list [--dir MIGRATIONS_DIR]`

Will show a list of all the migrations and their status in every env in the app.

The optional `MIGRATIONS_DIR` allows you to specify which migration directory to use other than one in the
current working directory.


### `migration revert MIGRATION_NAME [--env ENVIRONMENT_NAME] [--dir MIGRATIONS_DIR]`

This will copy the named migration from the Electric SQL server to replace the local one.

By default this will use the `default` environment, if you want to use a different one you can specify it with
`--env ENVIRONMENT_NAME`

The optional `MIGRATIONS_DIR` allows you to specify which migration directory to use other than one in the
current working directory.
5 changes: 5 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ if config_env() == :dev do
]
]
end

if config_env() == :test do
config :electric_sql_cli,
base_url: "http://localhost:4003/api/v1/"
end
10 changes: 10 additions & 0 deletions lib/electric/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ defmodule Electric.Client do
|> request(method: :post, url: path, json: payload)
end

@doc """
Send an authenticated PUT.request to the API with a JSON payload.
"""
def put("/" <> path, payload), do: put(path, payload)

def put(path, payload) do
base_req()
|> request(method: :put, url: path, json: payload)
end

@doc """
Make an authenticated request to the API..
"""
Expand Down
Loading

0 comments on commit f0e1631

Please sign in to comment.