Skip to content

Commit

Permalink
improvement: remove sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Jan 12, 2024
1 parent 87546cc commit 86c96c3
Show file tree
Hide file tree
Showing 57 changed files with 1,837 additions and 215 deletions.
1 change: 0 additions & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
:phoenix,
:ash,
:ash_postgres,
:ash_sqlite,
:ash_graphql,
:surface,
:ash_admin,
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ RUN apt-get install -y esl-erlang
RUN apt-get install -y apt-transport-https
RUN apt-get install -y ca-certificates
RUN apt-get install -y fuse3 libfuse3-dev libglib2.0-dev
RUN apt-get install -y sqlite3
COPY --from=flyio/litefs:0.5 /usr/local/bin/litefs /usr/local/bin/litefs
ENV NODE_MAJOR=16
RUN mkdir -p /etc/apt/keyrings
Expand Down
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Config

config :ash_hq,
ecto_repos: [AshHq.Repo, AshHq.SqliteRepo]
ecto_repos: [AshHq.Repo]

config :ash, allow_flow: true

Expand Down
6 changes: 0 additions & 6 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ config :git_ops,
manage_readme_version: "README.md",
version_tag_prefix: "v"

config :ash_hq, AshHq.SqliteRepo,
database: Path.join(__DIR__, "../ash-hq.db"),
port: 5432,
show_sensitive_data_on_connection_error: true,
pool_size: 10

config :ash_hq, :show_search_ranking, true

secret_key_base = "FxKFwVYhDFah3bLLXXqWdpdcLf5e5T1UyVM6XQp7kCt/Reg5yuAEI3upAVDRoP5e"
Expand Down
2 changes: 1 addition & 1 deletion config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ config :ash_hq, :analytics?, true
config :ash_hq, :download_ua_on_start, true

if config_env() == :prod do
config :ash_hq, AshHq.SqliteRepo,
config :ash_hq, AshHq.Repo,
database: "/litefs/db",
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")
end
Expand Down
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ config :ash_hq, AshHqWeb.Endpoint,
secret_key_base: secret_key_base,
server: false

config :ash_hq, AshHq.SqliteRepo,
config :ash_hq, AshHq.Repo,
database: Path.join(__DIR__, "../ash-hq#{System.get_env("MIX_TEST_PARTITION")}.db"),
pool_size: 10

Expand Down
4 changes: 0 additions & 4 deletions fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ processes = []
[env]
RELEASE_COOKIE = "VsipafjUVIYVpiYiljPg6DNZB8XiSnEf4zLi8WOf9bAU0XK7HuHQqA=="

[mounts]
source = "litefs"
destination = "/var/lib/litefs"

[[services]]
internal_port = 4000
protocol = "tcp"
Expand Down
1 change: 0 additions & 1 deletion lib/ash_hq/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ defmodule AshHq.Application do
AshHq.Vault,
# Start the Ecto repository
AshHq.Repo,
AshHq.SqliteRepo,
# Start the Telemetry supervisor
AshHqWeb.Telemetry,
# Start the PubSub system
Expand Down
42 changes: 21 additions & 21 deletions lib/ash_hq/docs/resources/dsl/dsl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ defmodule AshHq.Docs.Dsl do
@moduledoc false

use Ash.Resource,
data_layer: AshSqlite.DataLayer,
data_layer: AshPostgres.DataLayer,
extensions: [AshHq.Docs.Extensions.Search, AshHq.Docs.Extensions.RenderMarkdown]

sqlite do
postgres do
table "dsls"
repo AshHq.SqliteRepo
repo AshHq.Repo

references do
reference :library_version, on_delete: :delete
Expand All @@ -17,24 +17,6 @@ defmodule AshHq.Docs.Dsl do
migration_defaults optional_args: "[]"
end

search do
doc_attribute :doc

load_for_search [
:extension_module,
:library_name
]

weight_content(0.2)

sanitized_name_attribute :sanitized_path
use_path_for_name? true
end

render_markdown do
render_attributes doc: :doc_html
end

actions do
defaults [:update, :destroy]

Expand Down Expand Up @@ -65,6 +47,24 @@ defmodule AshHq.Docs.Dsl do
end
end

search do
doc_attribute :doc

load_for_search [
:extension_module,
:library_name
]

weight_content(0.2)

sanitized_name_attribute :sanitized_path
use_path_for_name? true
end

render_markdown do
render_attributes doc: :doc_html
end

attributes do
uuid_primary_key :id

Expand Down
6 changes: 3 additions & 3 deletions lib/ash_hq/docs/resources/extension/extension.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ defmodule AshHq.Docs.Extension do
@moduledoc false

use Ash.Resource,
data_layer: AshSqlite.DataLayer
data_layer: AshPostgres.DataLayer

sqlite do
postgres do
table "extensions"
repo AshHq.SqliteRepo
repo AshHq.Repo

references do
reference :library_version, on_delete: :delete
Expand Down
48 changes: 24 additions & 24 deletions lib/ash_hq/docs/resources/function/function.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,18 @@ defmodule AshHq.Docs.Function do
@moduledoc false

use Ash.Resource,
data_layer: AshSqlite.DataLayer,
data_layer: AshPostgres.DataLayer,
extensions: [AshHq.Docs.Extensions.Search, AshHq.Docs.Extensions.RenderMarkdown]

sqlite do
postgres do
table "functions"
repo AshHq.SqliteRepo
repo AshHq.Repo

references do
reference :library_version, on_delete: :delete
end
end

search do
doc_attribute :doc

load_for_search [
:version_name,
:library_name,
:module_name,
:call_name,
:library_id
]

type "Code"

show_docs_on :module_sanitized_name
end

render_markdown do
render_attributes doc: :doc_html, heads: :heads_html
header_ids? false
end

actions do
defaults [:update, :destroy]

Expand All @@ -56,6 +35,27 @@ defmodule AshHq.Docs.Function do
end
end

search do
doc_attribute :doc

load_for_search [
:version_name,
:library_name,
:module_name,
:call_name,
:library_id
]

type "Code"

show_docs_on :module_sanitized_name
end

render_markdown do
render_attributes doc: :doc_html, heads: :heads_html
header_ids? false
end

attributes do
uuid_primary_key :id

Expand Down
56 changes: 28 additions & 28 deletions lib/ash_hq/docs/resources/guide/guide.ex
Original file line number Diff line number Diff line change
@@ -1,23 +1,48 @@
defmodule AshHq.Docs.Guide do
@moduledoc false
use Ash.Resource,
data_layer: AshSqlite.DataLayer,
data_layer: AshPostgres.DataLayer,
extensions: [
AshHq.Docs.Extensions.Search,
AshHq.Docs.Extensions.RenderMarkdown,
AshGraphql.Resource,
AshAdmin.Resource
]

sqlite do
repo AshHq.SqliteRepo
postgres do
repo AshHq.Repo
table "guides"

references do
reference :library_version, on_delete: :delete
end
end

actions do
defaults [:create, :update, :destroy]

read :read do
primary? true

pagination keyset?: true,
offset?: true,
countable: true,
default_limit: 25,
required?: false
end

read :read_for_version do
argument :library_versions, {:array, :uuid} do
allow_nil? false
constraints max_length: 20, min_length: 1
end

pagination offset?: true, countable: true, default_limit: 25, required?: false

filter expr(library_version.id in ^arg(:library_versions))
end
end

search do
doc_attribute :text
show_docs_on [:sanitized_name, :sanitized_route]
Expand Down Expand Up @@ -46,31 +71,6 @@ defmodule AshHq.Docs.Guide do
end
end

actions do
defaults [:create, :update, :destroy]

read :read do
primary? true

pagination keyset?: true,
offset?: true,
countable: true,
default_limit: 25,
required?: false
end

read :read_for_version do
argument :library_versions, {:array, :uuid} do
allow_nil? false
constraints max_length: 20, min_length: 1
end

pagination offset?: true, countable: true, default_limit: 25, required?: false

filter expr(library_version.id in ^arg(:library_versions))
end
end

attributes do
uuid_primary_key :id

Expand Down
4 changes: 2 additions & 2 deletions lib/ash_hq/docs/resources/library/actions/import.ex
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ defmodule AshHq.Docs.Library.Actions.Import do
Ash.Query.for_read(AshHq.Docs.LibraryVersion, :read)
|> Ash.Query.filter(library_id == ^library.id and version == ^version)
) do
AshHq.SqliteRepo.transaction(
AshHq.Repo.transaction(
fn ->
library_version =
AshHq.Docs.LibraryVersion.build!(
Expand Down Expand Up @@ -107,7 +107,7 @@ defmodule AshHq.Docs.Library.Actions.Import do
|> Ash.Query.data_layer_query()
|> case do
{:ok, query} ->
AshHq.SqliteRepo.delete_all(query)
AshHq.Repo.delete_all(query)

other ->
raise "bad match #{inspect(other)}"
Expand Down
6 changes: 3 additions & 3 deletions lib/ash_hq/docs/resources/library/library.ex
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
defmodule AshHq.Docs.Library do
@moduledoc false
use Ash.Resource,
data_layer: AshSqlite.DataLayer,
data_layer: AshPostgres.DataLayer,
extensions: [AshOban]

sqlite do
postgres do
table "libraries"
repo AshHq.SqliteRepo
repo AshHq.Repo

migration_defaults module_prefixes: "[]", skip_versions: "[]"
end
Expand Down
16 changes: 8 additions & 8 deletions lib/ash_hq/docs/resources/library_version/library_version.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@ defmodule AshHq.Docs.LibraryVersion do
@moduledoc false

use Ash.Resource,
data_layer: AshSqlite.DataLayer,
data_layer: AshPostgres.DataLayer,
extensions: [AshHq.Docs.Extensions.Search, AshHq.Docs.Extensions.RenderMarkdown]

sqlite do
postgres do
table "library_versions"
repo AshHq.SqliteRepo
end

search do
name_attribute :version
load_for_search [:library_name, :library_display_name]
repo AshHq.Repo
end

actions do
Expand Down Expand Up @@ -91,6 +86,11 @@ defmodule AshHq.Docs.LibraryVersion do
end
end

search do
name_attribute :version
load_for_search [:library_name, :library_display_name]
end

attributes do
uuid_primary_key :id

Expand Down
Loading

0 comments on commit 86c96c3

Please sign in to comment.