Experimenting with CockroachDB

This commit is contained in:
Alex Gleason 2021-12-28 11:23:12 -06:00
parent 52a3f0f08b
commit 137cb8d96c
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
15 changed files with 53 additions and 42 deletions

View file

@ -3,8 +3,8 @@ defmodule Pleroma.Repo.Migrations.AddUserAndHub do
def change do def change do
alter table(:websub_client_subscriptions) do alter table(:websub_client_subscriptions) do
add(:hub, :string)
add(:user_id, references(:users)) add(:user_id, references(:users))
add(:hub, :string)
end end
end end
end end

View file

@ -6,15 +6,17 @@ defmodule Pleroma.Repo.Migrations.CaseInsensivtivity do
# inconsistent failures happen because of index on `email` column. # inconsistent failures happen because of index on `email` column.
def up do def up do
execute("create extension if not exists citext") # execute("create extension if not exists citext")
#
# alter table(:users) do
# modify(:email, :citext)
# end
#
# alter table(:users) do
# modify(:nickname, :citext)
# end
alter table(:users) do :ok
modify(:email, :citext)
end
alter table(:users) do
modify(:nickname, :citext)
end
end end
def down do def down do

View file

@ -3,12 +3,14 @@ defmodule Pleroma.Repo.Migrations.AddFTSIndexToActivities do
@disable_ddl_transaction true @disable_ddl_transaction true
def change do def change do
create( # create(
index(:activities, ["(to_tsvector('english', data->'object'->>'content'))"], # index(:activities, ["(to_tsvector('english', data->'object'->>'content'))"],
concurrently: true, # concurrently: true,
using: :gin, # using: :gin,
name: :activities_fts # name: :activities_fts
) # )
) # )
:ok
end end
end end

View file

@ -6,6 +6,6 @@ defmodule Pleroma.Repo.Migrations.AddRecipientsToActivities do
add(:recipients, {:array, :string}) add(:recipients, {:array, :string})
end end
create_if_not_exists(index(:activities, [:recipients], using: :gin)) # create_if_not_exists(index(:activities, [:recipients], using: :gin))
end end
end end

View file

@ -1,5 +1,6 @@
defmodule Pleroma.Repo.Migrations.MakeFollowingPostgresArray do defmodule Pleroma.Repo.Migrations.MakeFollowingPostgresArray do
use Ecto.Migration use Ecto.Migration
@disable_ddl_transaction true
def up do def up do
alter table(:users) do alter table(:users) do

View file

@ -3,20 +3,23 @@ defmodule Pleroma.Repo.Migrations.AddTrigramExtension do
require Logger require Logger
def up do def up do
Logger.warn("ATTENTION ATTENTION ATTENTION\n") # Logger.warn("ATTENTION ATTENTION ATTENTION\n")
#
# Logger.warn(
# "This will try to create the pg_trgm extension on your database. If your database user does NOT have the necessary rights, you will have to do it manually and re-run the migrations.\nYou can probably do this by running the following:\n"
# )
#
# Logger.warn(
# "sudo -u postgres psql pleroma_dev -c \"create extension if not exists pg_trgm\"\n"
# )
#
# execute("create extension if not exists pg_trgm")
Logger.warn( :ok
"This will try to create the pg_trgm extension on your database. If your database user does NOT have the necessary rights, you will have to do it manually and re-run the migrations.\nYou can probably do this by running the following:\n"
)
Logger.warn(
"sudo -u postgres psql pleroma_dev -c \"create extension if not exists pg_trgm\"\n"
)
execute("create extension if not exists pg_trgm")
end end
def down do def down do
execute("drop extension if exists pg_trgm") # execute("drop extension if exists pg_trgm")
:ok
end end
end end

View file

@ -2,8 +2,9 @@ defmodule Pleroma.Repo.Migrations.CreateUserTrigramIndex do
use Ecto.Migration use Ecto.Migration
def change do def change do
create_if_not_exists( # create_if_not_exists(
index(:users, ["(nickname || name) gist_trgm_ops"], name: :users_trigram_index, using: :gist) # index(:users, ["(nickname || name) gist_trgm_ops"], name: :users_trigram_index, using: :gist)
) # )
:ok
end end
end end

View file

@ -2,6 +2,7 @@ defmodule Pleroma.Repo.Migrations.AddListFollowIndex do
use Ecto.Migration use Ecto.Migration
def change do def change do
create_if_not_exists(index(:lists, [:following])) # create_if_not_exists(index(:lists, [:following]))
:ok
end end
end end

View file

@ -7,7 +7,7 @@ defmodule Pleroma.Repo.Migrations.AddRecipientsToAndCcFieldsToActivities do
add(:recipients_cc, {:array, :string}) add(:recipients_cc, {:array, :string})
end end
create_if_not_exists(index(:activities, [:recipients_to], using: :gin)) # create_if_not_exists(index(:activities, [:recipients_to], using: :gin))
create_if_not_exists(index(:activities, [:recipients_cc], using: :gin)) # create_if_not_exists(index(:activities, [:recipients_cc], using: :gin))
end end
end end

View file

@ -3,8 +3,8 @@ defmodule Pleroma.Repo.Migrations.RemoveRecipientsToAndCcFieldsFromActivities do
def up do def up do
alter table(:activities) do alter table(:activities) do
remove(:recipients_to) remove_if_exists(:recipients_to, {:array, :string})
remove(:recipients_cc) remove_if_exists(:recipients_cc, {:array, :string})
end end
end end

View file

@ -2,7 +2,8 @@ defmodule Pleroma.Repo.Migrations.AddUUIDExtension do
use Ecto.Migration use Ecto.Migration
def up do def up do
execute("create extension if not exists \"uuid-ossp\"") # execute("create extension if not exists \"uuid-ossp\"")
:ok
end end
def down, do: :ok def down, do: :ok

View file

@ -6,6 +6,6 @@ defmodule Pleroma.Repo.Migrations.AddTagsToUsers do
add(:tags, {:array, :string}) add(:tags, {:array, :string})
end end
create_if_not_exists(index(:users, [:tags], using: :gin)) # create_if_not_exists(index(:users, [:tags], using: :gin))
end end
end end

View file

@ -22,8 +22,8 @@ defmodule Pleroma.Repo.Migrations.UsersAndActivitiesFlakeId do
clippy = start_clippy_heartbeats() clippy = start_clippy_heartbeats()
# Lock both tables to avoid a running server to meddling with our transaction # Lock both tables to avoid a running server to meddling with our transaction
execute("LOCK TABLE activities;") # execute("LOCK TABLE activities;")
execute("LOCK TABLE users;") # execute("LOCK TABLE users;")
execute(""" execute("""
ALTER TABLE activities ALTER TABLE activities

View file

@ -3,7 +3,7 @@ defmodule Pleroma.Repo.Migrations.CreateHashtags do
def change do def change do
create_if_not_exists table(:hashtags) do create_if_not_exists table(:hashtags) do
add(:name, :citext, null: false) add(:name, :text, null: false)
timestamps() timestamps()
end end

View file

@ -9,7 +9,7 @@ defmodule Pleroma.Repo.Migrations.ChangeHashtagsNameToText do
def down do def down do
alter table(:hashtags) do alter table(:hashtags) do
modify(:name, :citext) modify(:name, :text)
end end
end end
end end