Skip to content

Commit

Permalink
Use post to create a project
Browse files Browse the repository at this point in the history
  • Loading branch information
loicknuchel committed Sep 30, 2024
1 parent 6ef2680 commit 1d0988a
Show file tree
Hide file tree
Showing 23 changed files with 139 additions and 108 deletions.
4 changes: 2 additions & 2 deletions backend/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ config :azimutt,
azimutt_github_issues_new: "https://github.com/azimuttapp/azimutt/issues/new",
environment: config_env(),
# TODO: find an automated process to build it
version: "2.1.6",
version_date: "2024-09-29T00:00:00.000Z",
version: "2.1.7",
version_date: "2024-09-30T00:00:00.000Z",
commit_hash: System.cmd("git", ["log", "-1", "--pretty=format:%h"]) |> elem(0) |> String.trim(),
commit_message: System.cmd("git", ["log", "-1", "--pretty=format:%s"]) |> elem(0) |> String.trim(),
commit_date: System.cmd("git", ["log", "-1", "--pretty=format:%aI"]) |> elem(0) |> String.trim(),
Expand Down
2 changes: 2 additions & 0 deletions backend/lib/azimutt_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,9 @@ defmodule AzimuttWeb.Router do
scope "/", AzimuttWeb do
pipe_through([:browser, :enforce_user_requirements, :elm_root_layout, AllowCrossOriginIframe])
get("/:organization_id/new", ElmController, :org_new)
post("/:organization_id/new", ElmController, :org_new)
get("/:organization_id/create", ElmController, :org_create)
post("/:organization_id/create", ElmController, :org_create)
get("/:organization_id/:project_id", ElmController, :project_show)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
You are almost setup to <span class="italic font-bold">explore and document your database</span>, just connect it now 👇️
</p>
<div class="mt-10 sm:mt-12">
<%= form_for @conn, Routes.elm_path(@conn, :org_create, @resource.organization.id), [method: :get, class: "sm:mx-auto sm:max-w-xl lg:mx-0"], fn _ -> %>
<%= form_for @conn, Routes.elm_path(@conn, :org_create, @resource.organization.id), [method: :post, class: "sm:mx-auto sm:max-w-xl lg:mx-0"], fn _ -> %>
<input type="hidden" name="storage" value="remote">
<input type="hidden" name="name" value={@resource.owner_name}>
<div class="sm:flex">
Expand Down
2 changes: 1 addition & 1 deletion backend/lib/azimutt_web/templates/heroku/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
You are almost setup to <span class="italic font-bold">explore and document your database</span>, just connect it now 👇️
</p>
<div class="mt-10 sm:mt-12">
<%= form_for @conn, Routes.elm_path(@conn, :org_create, @resource.organization.id), [method: :get, class: "sm:mx-auto sm:max-w-xl lg:mx-0"], fn _ -> %>
<%= form_for @conn, Routes.elm_path(@conn, :org_create, @resource.organization.id), [method: :post, class: "sm:mx-auto sm:max-w-xl lg:mx-0"], fn _ -> %>
<input type="hidden" name="storage" value="remote">
<input type="hidden" name="name" value={@resource.app}>
<div class="sm:flex">
Expand Down
2 changes: 2 additions & 0 deletions backend/lib/azimutt_web/templates/layout/root_elm.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
window.env = '<%= Azimutt.config(:environment) %>'
window.gateway_url = '<%= org_gateway || Azimutt.config(:gateway_url) %>'
window.role = '<%= member && member.role || :owner %>'
window.params = {}<%= for param <- ["database", "sql", "prisma", "json", "aml", "empty", "project", "sample", "name", "storage"] |> Enum.filter(fn p -> @conn.params[p] end) do %>
window.params.<%= param %> = '<%= @conn.params[param] %>'<% end %>
</script>
<%= if Azimutt.config(:sentry_frontend_dsn) do %>
<script>
Expand Down
4 changes: 2 additions & 2 deletions backend/lib/azimutt_web/templates/website/aml.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<img class="h-32" src={Routes.static_path(@conn, "/images/aml-by-azimutt.png")} alt="AML by Azimutt" />
<h1 class="mt-4 text-4xl font-bold tracking-tight text-gray-900 sm:text-5xl">The easiest DSL for database schemas</h1>
<p class="mt-6 text-lg leading-8 text-gray-600">
If you ever designed your database schema on a whiteboard, AML is made for you ❤️.
It's <b>fast to learn and write</b>, can be compiled in other dialects.
If you ever designed a database schema on a whiteboard,<br>
AML is made for you ❤️. It's <b>fast to learn and write</b>, and can be translated to other dialects.
</p>
<div class="mt-10 flex items-center gap-x-6">
<a href={aml_doc} target="_blank" rel="noopener" class="rounded-md bg-indigo-600 px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">Documentation</a>
Expand Down
6 changes: 5 additions & 1 deletion cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

Azimutt CLI ease your work with databases 😎

It works with **PostgreSQL**, **MySQL**, **MariaDB**, **SQL Server**, **Oracle**, **MongoDB**, **Couchbase**, **Snowflake**, **BigQuery** (can be extended on demand).
It works with: **PostgreSQL**, **MySQL**, **MariaDB**, **SQL Server**, **Oracle**, **MongoDB**, **Couchbase**, **Snowflake**, **BigQuery** (can be extended on demand).

It's a toolbox to interact with those databases but also [AML](../libs/aml), here are the main features:

Expand Down Expand Up @@ -118,6 +118,10 @@ Convert a dialect to another, supporting [AML](https://azimutt.app/aml), SQL (Po
npx azimutt@latest convert <file_path> --from <dialect> --to <dialect>
```

Input dialects: `aml`, `amlv1`, `json`

Output dialects: `aml`, `amlv1`, `postgres`, `mermaid`, `markdown`, `json`

Options:

- `--out <file_path>`: to choose the file to write (will be constructed otherwise)
Expand Down
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "azimutt",
"version": "0.1.29",
"version": "0.1.30",
"description": "Export database schema from relational or document databases. Import it to https://azimutt.app",
"keywords": [
"database",
Expand Down
2 changes: 1 addition & 1 deletion cli/src/explore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export async function launchExplore(url: string, instance: string, logger: Logge
// TODO: better error reporting when the import fails in Azimutt
const parsed: DatabaseUrlParsed = parseDatabaseUrl(url)
track('cli__explore__run', {version, database: parsed.kind}, 'cli').then(() => {})
const azimuttUrl = `${instance}/create?database=${encodeURIComponent(url)}`
const azimuttUrl = `${instance}/create#${encodeURIComponent(url)}`
// const azimuttUrl = `${instance}/embed?database-source=${encodeURIComponent(url)}&mode=full`
// https://azimutt.app/embed?database-source=postgresql://postgres:postgres@localhost/azimutt_dev&mode=full
// const azimuttUrl = `https://azimutt.app/create?database=${encodeURIComponent(url)}&gateway=http://localhost:4177`
Expand Down
2 changes: 1 addition & 1 deletion cli/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = '0.1.29' // FIXME: `process.env.npm_package_version` is not available :/
export const version = '0.1.30' // FIXME: `process.env.npm_package_version` is not available :/
18 changes: 2 additions & 16 deletions frontend/src/Pages/Create.elm
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
module Pages.Create exposing (Model, Msg, page)

import Gen.Params.Create exposing (Params)
import Models.OrganizationId exposing (OrganizationId)
import Page
import PagesComponents.Create.Init as Init
import PagesComponents.Create.Element as Element
import PagesComponents.Create.Models as Models
import PagesComponents.Create.Subscriptions as Subscriptions
import PagesComponents.Create.Updates as Updates
import PagesComponents.Create.Views as Views
import Request
import Shared


page : Shared.Model -> Request.With Params -> Page.With Model Msg
page shared req =
let
urlOrganization : Maybe OrganizationId
urlOrganization =
Nothing
in
Page.element
{ init = Init.init urlOrganization
, update = Updates.update req shared.now shared.projects shared.projectsLoaded urlOrganization
, view = Views.view
, subscriptions = Subscriptions.subscriptions
}
Element.init Nothing shared req


type alias Model =
Expand Down
18 changes: 2 additions & 16 deletions frontend/src/Pages/New.elm
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
module Pages.New exposing (Model, Msg, page)

import Gen.Params.New exposing (Params)
import Models.OrganizationId exposing (OrganizationId)
import Page
import PagesComponents.New.Init as Init
import PagesComponents.New.Element as Element
import PagesComponents.New.Models as Models exposing (Msg)
import PagesComponents.New.Subscriptions as Subscriptions
import PagesComponents.New.Updates as Updates
import PagesComponents.New.Views as Views
import Request
import Shared


page : Shared.Model -> Request.With Params -> Page.With Model Msg
page shared req =
let
urlOrganization : Maybe OrganizationId
urlOrganization =
Nothing
in
Page.element
{ init = Init.init urlOrganization req.query
, update = Updates.update req shared.now shared.projects urlOrganization
, view = Views.view shared req.url urlOrganization
, subscriptions = Subscriptions.subscriptions
}
Element.init Nothing shared req


type alias Model =
Expand Down
18 changes: 2 additions & 16 deletions frontend/src/Pages/Organization_/Create.elm
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
module Pages.Organization_.Create exposing (Model, Msg, page)

import Gen.Params.Organization_.Create exposing (Params)
import Models.OrganizationId exposing (OrganizationId)
import Page
import PagesComponents.Create.Init as Init
import PagesComponents.Create.Element as Element
import PagesComponents.Create.Models as Models
import PagesComponents.Create.Subscriptions as Subscriptions
import PagesComponents.Create.Updates as Updates
import PagesComponents.Create.Views as Views
import Request
import Shared


page : Shared.Model -> Request.With Params -> Page.With Model Msg
page shared req =
let
urlOrganization : Maybe OrganizationId
urlOrganization =
Just req.params.organization
in
Page.element
{ init = Init.init urlOrganization
, update = Updates.update req shared.now shared.projects shared.projectsLoaded urlOrganization
, view = Views.view
, subscriptions = Subscriptions.subscriptions
}
Element.init (Just req.params.organization) shared req


type alias Model =
Expand Down
18 changes: 2 additions & 16 deletions frontend/src/Pages/Organization_/New.elm
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
module Pages.Organization_.New exposing (Model, Msg, page)

import Gen.Params.Organization_.New exposing (Params)
import Models.OrganizationId exposing (OrganizationId)
import Page
import PagesComponents.New.Init as Init
import PagesComponents.New.Element as Element
import PagesComponents.New.Models as Models exposing (Msg)
import PagesComponents.New.Subscriptions as Subscriptions
import PagesComponents.New.Updates as Updates
import PagesComponents.New.Views as Views
import Request
import Shared


page : Shared.Model -> Request.With Params -> Page.With Model Msg
page shared req =
let
urlOrganization : Maybe OrganizationId
urlOrganization =
Just req.params.organization
in
Page.element
{ init = Init.init urlOrganization req.query
, update = Updates.update req shared.now shared.projects urlOrganization
, view = Views.view shared req.url urlOrganization
, subscriptions = Subscriptions.subscriptions
}
Element.init (Just req.params.organization) shared req


type alias Model =
Expand Down
39 changes: 39 additions & 0 deletions frontend/src/PagesComponents/Create/Element.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module PagesComponents.Create.Element exposing (init)

import Dict exposing (Dict)
import Models.OrganizationId exposing (OrganizationId)
import Page
import PagesComponents.Create.Init as Init
import PagesComponents.Create.Models as Models
import PagesComponents.Create.Subscriptions as Subscriptions
import PagesComponents.Create.Updates as Updates
import PagesComponents.Create.Views as Views
import Request
import Shared


init : Maybe OrganizationId -> Shared.Model -> Request.With params -> Page.With Model Msg
init urlOrganization shared req =
let
hash : Dict String String
hash =
req.url.fragment |> Maybe.map (\h -> Dict.fromList [ ( "database", h ) ]) |> Maybe.withDefault Dict.empty

params : Dict String String
params =
hash |> Dict.union shared.params |> Dict.union req.query
in
Page.element
{ init = Init.init urlOrganization
, update = Updates.update req params shared.now shared.projects shared.projectsLoaded urlOrganization
, view = Views.view
, subscriptions = Subscriptions.subscriptions
}


type alias Model =
Models.Model


type alias Msg =
Models.Msg
30 changes: 15 additions & 15 deletions frontend/src/PagesComponents/Create/Updates.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module PagesComponents.Create.Updates exposing (update)

import Conf
import DataSources.JsonMiner.JsonAdapter as JsonAdapter
import Dict
import Dict exposing (Dict)
import Gen.Route as Route
import Libs.Dict as Dict
import Libs.Maybe as Maybe
Expand Down Expand Up @@ -31,31 +31,31 @@ import Time
import Track


update : Request.With params -> Time.Posix -> List ProjectInfo -> Bool -> Maybe OrganizationId -> Msg -> Model -> ( Model, Cmd Msg )
update req now projects projectsLoaded urlOrganization msg model =
update : Request.With params -> Dict String String -> Time.Posix -> List ProjectInfo -> Bool -> Maybe OrganizationId -> Msg -> Model -> ( Model, Cmd Msg )
update req params now projects projectsLoaded urlOrganization msg model =
case msg of
InitProject ->
if projectsLoaded then
let
name : ProjectName
name =
req.query |> Dict.getOrElse "name" Conf.constants.newProjectName
params |> Dict.getOrElse "name" Conf.constants.newProjectName

storage : Maybe ProjectStorage
storage =
req.query |> Dict.get "storage" |> Maybe.andThen ProjectStorage.fromString
params |> Dict.get "storage" |> Maybe.andThen ProjectStorage.fromString
in
( (req.query |> Dict.get "database" |> Maybe.map (\_ -> { model | databaseSource = Just (DatabaseSource.init Nothing (createProject urlOrganization projects storage name)) }))
|> Maybe.orElse (req.query |> Dict.get "sql" |> Maybe.map (\_ -> { model | sqlSource = Just (SqlSource.init Nothing (Tuple.second >> createProject urlOrganization projects storage name)) }))
|> Maybe.orElse (req.query |> Dict.get "prisma" |> Maybe.map (\_ -> { model | prismaSource = Just (PrismaSource.init Nothing (createProject urlOrganization projects storage name)) }))
|> Maybe.orElse (req.query |> Dict.get "json" |> Maybe.map (\_ -> { model | jsonSource = Just (JsonSource.init Nothing (createProject urlOrganization projects storage name)) }))
|> Maybe.orElse (req.query |> Dict.get "aml" |> Maybe.map (\aml -> { model | amlSource = Just { content = aml, callback = createProject urlOrganization projects storage name } }))
( (params |> Dict.get "database" |> Maybe.map (\_ -> { model | databaseSource = Just (DatabaseSource.init Nothing (createProject urlOrganization projects storage name)) }))
|> Maybe.orElse (params |> Dict.get "sql" |> Maybe.map (\_ -> { model | sqlSource = Just (SqlSource.init Nothing (Tuple.second >> createProject urlOrganization projects storage name)) }))
|> Maybe.orElse (params |> Dict.get "prisma" |> Maybe.map (\_ -> { model | prismaSource = Just (PrismaSource.init Nothing (createProject urlOrganization projects storage name)) }))
|> Maybe.orElse (params |> Dict.get "json" |> Maybe.map (\_ -> { model | jsonSource = Just (JsonSource.init Nothing (createProject urlOrganization projects storage name)) }))
|> Maybe.orElse (params |> Dict.get "aml" |> Maybe.map (\aml -> { model | amlSource = Just { content = aml, callback = createProject urlOrganization projects storage name } }))
|> Maybe.withDefault model
, (req.query |> Dict.get "database" |> Maybe.map (DatabaseSource.GetSchema >> DatabaseSourceMsg >> T.send))
|> Maybe.orElse (req.query |> Dict.get "sql" |> Maybe.map (SqlSource.GetRemoteFile >> SqlSourceMsg >> T.send))
|> Maybe.orElse (req.query |> Dict.get "prisma" |> Maybe.map (PrismaSource.GetRemoteFile >> PrismaSourceMsg >> T.send))
|> Maybe.orElse (req.query |> Dict.get "json" |> Maybe.map (JsonSource.GetRemoteFile >> JsonSourceMsg >> T.send))
|> Maybe.orElse (req.query |> Dict.get "aml" |> Maybe.map (AmlSourceMsg >> T.send))
, (params |> Dict.get "database" |> Maybe.map (DatabaseSource.GetSchema >> DatabaseSourceMsg >> T.send))
|> Maybe.orElse (params |> Dict.get "sql" |> Maybe.map (SqlSource.GetRemoteFile >> SqlSourceMsg >> T.send))
|> Maybe.orElse (params |> Dict.get "prisma" |> Maybe.map (PrismaSource.GetRemoteFile >> PrismaSourceMsg >> T.send))
|> Maybe.orElse (params |> Dict.get "json" |> Maybe.map (JsonSource.GetRemoteFile >> JsonSourceMsg >> T.send))
|> Maybe.orElse (params |> Dict.get "aml" |> Maybe.map (AmlSourceMsg >> T.send))
|> Maybe.withDefault (NoSourceMsg storage name |> T.send)
)

Expand Down
39 changes: 39 additions & 0 deletions frontend/src/PagesComponents/New/Element.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module PagesComponents.New.Element exposing (init)

import Dict exposing (Dict)
import Models.OrganizationId exposing (OrganizationId)
import Page
import PagesComponents.New.Init as Init
import PagesComponents.New.Models as Models
import PagesComponents.New.Subscriptions as Subscriptions
import PagesComponents.New.Updates as Updates
import PagesComponents.New.Views as Views
import Request
import Shared


init : Maybe OrganizationId -> Shared.Model -> Request.With params -> Page.With Model Msg
init urlOrganization shared req =
let
hash : Dict String String
hash =
req.url.fragment |> Maybe.map (\h -> Dict.fromList [ ( "database", h ) ]) |> Maybe.withDefault Dict.empty

params : Dict String String
params =
hash |> Dict.union shared.params |> Dict.union req.query
in
Page.element
{ init = Init.init urlOrganization params
, update = Updates.update req params shared.now shared.projects urlOrganization
, view = Views.view shared req.url urlOrganization
, subscriptions = Subscriptions.subscriptions
}


type alias Model =
Models.Model


type alias Msg =
Models.Msg
Loading

0 comments on commit 1d0988a

Please sign in to comment.