Skip to content

Commit

Permalink
Allow for sqlite ecto.
Browse files Browse the repository at this point in the history
Make migrations compatible with sqlite.

Update the migrations for sqlite.

Update javascript dependencies.

Fix error with null permissions due to lack of loading the user id.

Update dependencies versions in mix.exs and mix.lock
  • Loading branch information
fire committed Apr 9, 2024
1 parent 2a66b95 commit 7873ad8
Show file tree
Hide file tree
Showing 19 changed files with 79 additions and 61 deletions.
62 changes: 33 additions & 29 deletions .github/workflows/uro_release_x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,36 @@ jobs:
runs-on: ubuntu-latest

container:
image: hexpm/elixir:1.12.3-erlang-24.0.5-ubuntu-focal-20210325
image: hexpm/elixir:1.16.2-erlang-24.3.4.17-ubuntu-focal-20240216

steps:
- uses: actions/checkout@v2

- name: Install system dependencies
run: |
apt update
apt install -y build-essential erlang-dev curl git
- name: Install foundationdb dependency
run: |
set -e
curl -L https://github.com/apple/foundationdb/releases/download/7.1.53/foundationdb-clients_7.1.53-1_amd64.deb --output fdb-client.deb
dpkg -i fdb-client.deb
curl -L https://github.com/apple/foundationdb/releases/download/7.1.53/foundationdb-server_7.1.53-1_amd64.deb --output fdb-server.deb
dpkg -i fdb-server.deb
apt update && sudo apt install -y libfuse3-dev execstack
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- name: Set up Elixir
run: |
mix local.hex --force
mix local.rebar --force
- name: Install system dependencies
run: |
apt update
apt install -y build-essential erlang-dev curl
- name: Restore dependencies cache
uses: actions/cache@v2
with:
Expand All @@ -39,31 +54,20 @@ jobs:
- name: Compile code
run: mix compile

- name: Install CockroachDB
run: |
curl -s https://binaries.cockroachdb.com/cockroach-v23.2.0-rc.1.linux-amd64.tgz | tar xvz
mkdir -p ${{ runner.temp }}/cockroach
cp cockroach-v23.2.0-rc.1.linux-amd64/cockroach ${{ runner.temp }}/cockroach/
echo "${{ runner.temp }}/cockroach" >> $GITHUB_PATH
- name: Start CockroachDB
run: |
cockroach start-single-node --insecure --background
- name: Wait for CockroachDB to be ready
run: |
until cockroach sql --execute="SELECT 1" --insecure; do sleep 1; done
- name: Setup Database
run: MIX_ENV=test mix ecto.setup

- name: Run Seeds
run: MIX_ENV=test mix run priv/repo/test_seeds.exs

- name: Run tests
id: test_step
continue-on-error: true
run: mix test | tee test_output.txt; test ${PIPESTATUS[0]} -eq 0
id: test_step
run: |
set -e
chmod +x ./rust_src/target/release/mvstore
export RUST_LOG=error
./rust_src/target/release/mvstore --data-plane 127.0.0.1:7000 --admin-api 127.0.0.1:7001 --metadata-prefix mvstore-test --raw-data-prefix m --auto-create-namespace --cluster /etc/foundationdb/fdb.cluster &
sleep 1
curl http://localhost:7001/api/create_namespace -d '{"key":"uro_dev.sqlite3","metadata":""}'
sleep 1
MIX_ENV=test mix ecto.setup
MIX_ENV=test mix run priv/repo/test_seeds.exs
mix test | tee test_output.txt; test ${PIPESTATUS[0]} -eq 0
- name: Upload test results
uses: actions/upload-artifact@v2
Expand Down
9 changes: 3 additions & 6 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ db_hostname = System.get_env("URO_LOCAL_DB") || "localhost"

# Configure your database
config :uro, Uro.Repo,
adapter: Ecto.Adapaters.Postgres,
username: "root",
password: "",
port: "26257",
database: "uro_dev",
hostname: db_hostname,
adapter: Ecto.Adapters.SQLite3,
database: "uro_dev.sqlite3",
datetime_type: :text_datetime,
show_sensitive_data_on_connection_error: true,
pool_size: 10

Expand Down
6 changes: 3 additions & 3 deletions lib/uro/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ defmodule Uro.Accounts do
|> Repo.preload(@user_associated_schemas)
end

def create_user_privilege_ruleset_for_user(user, attrs \\ %{}) do
def create_user_privilege_ruleset_for_user(user) do
user
|> Ecto.build_assoc(:user_privilege_ruleset, attrs)
|> Ecto.build_assoc(:user_privilege_ruleset, %UserPrivilegeRuleset{user_id: user.id})
|> Repo.insert()
end

def create_associated_entries_for_user(user) do
user
|> create_user_privilege_ruleset_for_user
|> create_user_privilege_ruleset_for_user()

user
end
Expand Down
3 changes: 3 additions & 0 deletions lib/uro/accounts/user_privilege_ruleset.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ defmodule Uro.Accounts.UserPrivilegeRuleset do
@derive {Jason.Encoder,
only: [:is_admin, :can_upload_avatars, :can_upload_maps, :can_upload_props]}

@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
@derive {Phoenix.Param, key: :id}
schema "user_privilege_rulesets" do
belongs_to :user, Uro.Accounts.User, foreign_key: :user_id, type: :binary_id

Expand Down
3 changes: 3 additions & 0 deletions lib/uro/events/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ defmodule Uro.Events.Event do
use Ecto.Schema
import Ecto.Changeset

@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
@derive {Phoenix.Param, key: :id}
schema "events" do
field :description, :string
field :name, :string
Expand Down
2 changes: 1 addition & 1 deletion lib/uro/repo.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Uro.Repo do
use Ecto.Repo,
otp_app: :uro,
adapter: Ecto.Adapters.Postgres
adapter: Ecto.Adapters.SQLite3

use Scrivener, page_size: 10
end
3 changes: 3 additions & 0 deletions lib/uro/v_sekai/shard.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ defmodule Uro.VSekai.Shard do
use Ecto.Schema
import Ecto.Changeset

@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
@derive {Phoenix.Param, key: :id}
schema "shards" do
belongs_to :user, Uro.Accounts.User, foreign_key: :user_id, type: :binary_id

Expand Down
8 changes: 5 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ defmodule Uro.MixProject do
{:phoenix_ecto, "~> 4.4"},
{:phoenix_live_view, "~> 0.20.3"},
{:phoenix_view, "~> 2.0"},
{:ecto_sql, "~> 3.5.3"},
{:ecto_sql, "~> 3.11"},
{:postgrex, ">= 0.0.0"},
{:phoenix_html, "~> 3.3"},
{:phoenix_live_reload, "~> 1.3", only: :dev},
Expand All @@ -50,11 +50,13 @@ defmodule Uro.MixProject do
{:bcrypt_elixir, "~> 2.3"},
{:pow, "~> 1.0"},
{:email_checker, "~> 0.1.4"},
{:pow_assent, "~> 0.4.10"},
{:ssl_verify_fun, "~> 1.1"},
{:pow_assent, "~> 0.4.18"},
{:ssl_verify_fun, "~> 1.1.6"},
{:phoenix_swagger, "~> 0.8.3"},
{:ex_json_schema, "~> 0.7.4"},
{:remote_ip, "~> 1.0"},
{:ecto_sqlite3, "~> 0.13.0"},
{:exqlite, [env: :prod, git: "https://github.com/V-Sekai/elixir-mvsqlite.git", override: true]},
{:waffle, "~> 1.1"},
{:waffle_ecto, "~> 0.0.10"},
{:swoosh, "~> 1.3"},
Expand Down
Loading

0 comments on commit 7873ad8

Please sign in to comment.