Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sqlite 04 #92

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 41 additions & 23 deletions .github/workflows/uro_release_x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install system dependencies
run: |
apt update
apt install -y build-essential erlang-dev curl
apt install -y build-essential erlang-dev curl git libclang1

- name: Set up Elixir
run: |
Expand All @@ -40,6 +40,30 @@ jobs:
cp cockroach-v23.2.0-rc.1.linux-amd64/cockroach ${{ runner.temp }}/cockroach/
echo "${{ runner.temp }}/cockroach" >> $GITHUB_PATH

- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- 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 && apt install -y libfuse3-dev execstack

- name: Install dependencies
run: mix deps.get

- name: Compile code
run: mix compile

- name: Install dependencies
run: mix deps.get

- name: Start CockroachDB
run: |
cockroach start-single-node --insecure --background
Expand All @@ -54,9 +78,16 @@ jobs:
- name: Compile code
run: mix compile

- name: Run tests
- uses: actions/checkout@v2
with:
repository: V-Sekai/elixir-mvsqlite
path: elixir_mvsqlite

- run: cargo build --locked --release -p mvstore --manifest-path elixir_mvsqlite/rust_src/Cargo.toml

- name: Run test sqlite fdb
continue-on-error: true
id: test_step
id: test_step_sqlite
run: |
set -e
chmod +x elixir_mvsqlite/rust_src/target/release/mvstore
Expand All @@ -65,30 +96,17 @@ jobs:
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
mix deps.get exqlite
URO_DB_TYPE=sqlite MIX_ENV=test mix ecto.setup
URO_DB_TYPE=sqlite MIX_ENV=test mix run priv/repo/test_seeds.exs
URO_DB_TYPE=sqlite mix test | tee test_output_sqlite.txt; test ${PIPESTATUS[0]} -eq 0

- name: Upload test results
- name: Upload sqlite fdb test results
continue-on-error: true
uses: actions/upload-artifact@v2
with:
name: test-results
path: test_output.txt

- name: Parse and check test results
continue-on-error: true
if: always()
run: |
echo "Parsing test results..."
TEST_OUTPUT=$(grep -oP '\d+ tests, \K\d+(?= failures)' test_output.txt)
echo "TEST_FAILURES=$TEST_OUTPUT" >> $GITHUB_ENV

if [ "$TEST_OUTPUT" -le 102 ]; then
echo "Test failures are within the acceptable range."
else
echo "Too many test failures: $TEST_OUTPUT"
exit 1
fi
path: test_output_sqlite.txt

- name: Check formatted code
run: mix format --check-formatted
76 changes: 54 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,69 +1,101 @@
# Uro

## Local Dev
It's possible to run the entire stack locally with docker-compose by running `docker-compose up`

It's possible to run the entire stack locally with docker-compose by running `docker-compose up`

To start your Phoenix server:

* Install dependencies with `mix deps.get`
* Create and migrate your database with `mix ecto.setup`
* Install Node.js dependencies with `cd assets && npm install`
* Start Phoenix endpoint with `mix phx.server`
- Install dependencies with `mix deps.get`
- Create and migrate your database with `mix ecto.setup`
- Install Node.js dependencies with `cd assets && npm install`
- Start Phoenix endpoint with `mix phx.server`

Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
Now, you can visit [`localhost:4000`](http://localhost:4000) from your browser.

Ready to run in production? Please [check our deployment guides](https://hexdocs.pm/phoenix/deployment.html).

## Learn more

* Official website: https://www.phoenixframework.org/
* Guides: https://hexdocs.pm/phoenix/overview.html
* Docs: https://hexdocs.pm/phoenix
* Forum: https://elixirforum.com/c/phoenix-forum
* Source: https://github.com/phoenixframework/phoenix
- Official website: https://www.phoenixframework.org/
- Guides: https://hexdocs.pm/phoenix/overview.html
- Docs: https://hexdocs.pm/phoenix
- Forum: https://elixirforum.com/c/phoenix-forum
- Source: https://github.com/phoenixframework/phoenix

## How to create a test environment?
## How do you create a test environment?

```bash
cockroach start-single-node --insecure --background
export MIX_ENV=dev
export MIX_ENV=dev
mix deps.get
mix ecto.drop
mix ecto.setup
mix run priv/repo/test_seeds.exs
iex -S mix phx.server
```

Note that `bcrypt_elixir` will require a working compiler in the PATH. On a Windows system with Visual Studio, you will want to run `mix deps.compile --force` from within a "x64 Native Tools Command Prompt" or cmd with vcvarsall.bat (may fail to build the rest of uro) then return to a bash shell for the rest of the build.

## How do we create a test environment for the Macos?

```bash
# Start in v-sekai/v-sekai-other-world
cd mvsqlite
cargo build --locked --release -p mvstore --manifest-path Cargo.toml
export RUST_LOG=error
DYLD_FALLBACK_LIBRARY_PATH=/usr/local/lib ./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 /usr/local/etc/foundationdb/fdb.cluster &
```

```bash
# create database
sleep 1
curl http://localhost:7001/api/create_namespace -d '{"key":"uro_dev.sqlite3","metadata":""}'
sleep 1
```

```
cd SERVICE_uro_sqlite_fdb
MIX_ENV=test mix ecto.setup
MIX_ENV=test mix run priv/repo/test_seeds.exs
MIX_ENV=test mix test | tee test_output.txt; test ${PIPESTATUS[0]} -eq 0
```

## Log into Cockroachdb sql shell

`./cockroach sql --database="uro_dev" --insecure`

You may approve all pending email verifications using:
You may approve all pending email verifications using the following:

```
```sql
update users set email_confirmation_token=null, email_confirmed_at=NOW() where true;
```

And you can grant upload privileges for all users using
```
You can grant upload privileges to all users using

```sql
update user_privilege_rulesets set can_upload_avatars=true, can_upload_maps=true, can_upload_props=true where true;
```

Finally, to enable admin access for a specific user id:
```
Finally, to enable admin access for a specific user ID:

```sql
update user_privilege_rulesets set is_admin=true where user_id = '12345678-abcd-...';
```

## Host local CDN for testing

By default, the `dev` environment will store assets in `priv/waffle/private` directory, and the client expects this to be available on port 80. To serve the CDN content on port 80:

```
```bash
cd priv/waffle/private
python -m http.server 80
```

Windows allows any user to serve port 80 by default, but on other operating systems the above should be run with sudo.
Windows allows any user to serve port 80 by default, but the above should be run with sudo on other operating systems.

# Mvsqlite

```
UPDATE users SET email_confirmation_token = NULL, email_confirmed_at = datetime('now') WHERE 1;
```
3 changes: 1 addition & 2 deletions assets/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# is restricted to this project.

# General application configuration
use Mix.Config
import Config

config :hammer,
backend: {Hammer.Backend.ETS, [expiry_ms: 60_000 * 60 * 4, cleanup_interval_ms: 60_000 * 10]}
Expand Down
30 changes: 21 additions & 9 deletions config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import Config

db_hostname = System.get_env("URO_LOCAL_DB") || "localhost"
db_type = System.get_env("URO_DB_TYPE") || "postgresql"

# Configure your database
config :uro, Uro.Repo,
adapter: Ecto.Adapaters.Postgres,
username: "root",
password: "",
port: "26257",
database: "uro_dev",
hostname: db_hostname,
show_sensitive_data_on_connection_error: true,
pool_size: 10
case db_type do
"postgresql" ->
config :uro, Uro.Repo,
adapter: Ecto.Adapters.Postgres,
username: "root",
password: "",
port: "26257",
database: "uro_dev",
hostname: db_hostname,
show_sensitive_data_on_connection_error: true,
pool_size: 10

"sqlite" ->
config :uro, Uro.Repo,
adapter: Ecto.Adapters.SQLite3,
database: "uro_dev.sqlite3",
datetime_type: :text_datetime,
show_sensitive_data_on_connection_error: true,
pool_size: 10
end

# For development, we disable any cache and enable
# debugging and code reloading.
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
6 changes: 3 additions & 3 deletions lib/uro/accounts/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ defmodule Uro.Accounts.User do
wildcard_search = "%#{search_term}%"

from user in query,
where: ilike(user.username, ^wildcard_search),
or_where: ilike(user.display_name, ^wildcard_search),
or_where: ilike(user.email, ^wildcard_search)
where: like(user.username, ^wildcard_search),
or_where: like(user.display_name, ^wildcard_search),
or_where: like(user.email, ^wildcard_search)
end
end
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
3 changes: 3 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ defmodule Uro.MixProject do
{: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
4 changes: 2 additions & 2 deletions priv/repo/migrations/20200514192900_create_users.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ defmodule Uro.Repo.Migrations.CreateUsers do
use Ecto.Migration

def change do
create table(:users, primary_key: false) do
create table(:users, primary_key: false, options: "STRICT, WITHOUT ROWID") do
add :id, :uuid, primary_key: true
add :email, :string, null: false
add :password_hash, :string

add :username, :string
add :display_name, :string

add :email_notifications, :bool, default: false
add :email_notifications, :boolean, default: false

add :profile_picture, :string

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Uro.Repo.Migrations.CreateUserIdentities do
use Ecto.Migration

def change do
create table(:user_identities, primary_key: false) do
create table(:user_identities, primary_key: false, options: "STRICT, WITHOUT ROWID") do
add :id, :uuid, primary_key: true
add :provider, :string, null: false
add :uid, :string, null: false
Expand Down
Loading
Loading