Skip to content
Merged
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
48 changes: 48 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

permissions:
contents: read

jobs:
test:
name: Build and Test
runs-on: ubuntu-latest

env:
MIX_ENV: test
ELIXIR_VERSION: "1.17.3"
OTP_VERSION: "27.2"

steps:
- uses: actions/checkout@v4

- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: ${{ env.ELIXIR_VERSION }}
otp-version: ${{ env.OTP_VERSION }}

- name: Cache deps
uses: actions/cache@v4
with:
path: |
deps
_build
key: ${{ runner.os }}-mix-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ hashFiles('mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-

- name: Install dependencies
run: mix deps.get

- name: Compile
run: mix compile --warnings-as-errors

- name: Run tests
run: mix test
38 changes: 38 additions & 0 deletions test/items_api/migration_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
defmodule ItemsApi.MigrationTest do
use ExUnit.Case, async: false

setup do
:ok = Ecto.Adapters.SQL.Sandbox.checkout(ItemsApi.Repo)
:ok
end

describe "auto-migration on startup" do
test "items table exists after application start" do
# The application has already started (mix test starts it via mod:),
# so migrations should have run. Verify the items table exists.
{:ok, %{rows: tables}} =
Ecto.Adapters.SQL.query(ItemsApi.Repo, "SELECT name FROM sqlite_master WHERE type='table' AND name='items'")

assert tables == [["items"]]
end

test "items table has expected columns" do
{:ok, %{rows: columns}} =
Ecto.Adapters.SQL.query(ItemsApi.Repo, "PRAGMA table_info(items)")

column_names = Enum.map(columns, fn [_cid, name | _rest] -> name end)
assert "id" in column_names
assert "name" in column_names
assert "description" in column_names
assert "inserted_at" in column_names
end

test "re-running migrations is idempotent" do
migrations_path = Application.app_dir(:items_api, "priv/repo/migrations")
# Running migrations again should not crash
result = Ecto.Migrator.run(ItemsApi.Repo, migrations_path, :up, all: true)
# Returns empty list when all migrations already applied
assert result == []
end
end
end
Loading