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

Set admin and moderator to non-null and false by default #302

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions server/lib/orcasite/accounts/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ defmodule Orcasite.Accounts.User do
attribute :hashed_password, :string, allow_nil?: false, sensitive?: true
attribute :first_name, :string
attribute :last_name, :string
attribute :admin, :boolean
attribute :moderator, :boolean
attribute :admin, :boolean, default: false, allow_nil?: false
attribute :moderator, :boolean, default: false, allow_nil?: false

create_timestamp :inserted_at
update_timestamp :updated_at
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
defmodule Orcasite.Repo.Migrations.UpdateUserAdminAndModDefaultFalse do
@moduledoc """
Updates resources based on their most recent snapshots.

This file was autogenerated with `mix ash_postgres.generate_migrations`
"""

use Ecto.Migration

def up do
execute "update users set admin = 'f' where admin is null;"
execute "update users set moderator = 'f' where moderator is null;"

flush()

alter table(:users) do
modify :moderator, :boolean, null: false, default: false
modify :admin, :boolean, null: false, default: false
end
end

def down do
alter table(:users) do
modify :admin, :boolean, null: true, default: nil
modify :moderator, :boolean, null: true, default: nil
end
end
end
118 changes: 118 additions & 0 deletions server/priv/resource_snapshots/repo/users/20240110222226.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
"attributes": [
{
"default": "nil",
"size": null,
"type": "uuid",
"source": "id",
"references": null,
"allow_nil?": false,
"generated?": false,
"primary_key?": true
},
{
"default": "nil",
"size": null,
"type": "citext",
"source": "email",
"references": null,
"allow_nil?": false,
"generated?": false,
"primary_key?": false
},
{
"default": "nil",
"size": null,
"type": "text",
"source": "hashed_password",
"references": null,
"allow_nil?": false,
"generated?": false,
"primary_key?": false
},
{
"default": "nil",
"size": null,
"type": "text",
"source": "first_name",
"references": null,
"allow_nil?": true,
"generated?": false,
"primary_key?": false
},
{
"default": "nil",
"size": null,
"type": "text",
"source": "last_name",
"references": null,
"allow_nil?": true,
"generated?": false,
"primary_key?": false
},
{
"default": "false",
"size": null,
"type": "boolean",
"source": "admin",
"references": null,
"allow_nil?": false,
"generated?": false,
"primary_key?": false
},
{
"default": "false",
"size": null,
"type": "boolean",
"source": "moderator",
"references": null,
"allow_nil?": false,
"generated?": false,
"primary_key?": false
},
{
"default": "fragment(\"now()\")",
"size": null,
"type": "utc_datetime_usec",
"source": "inserted_at",
"references": null,
"allow_nil?": false,
"generated?": false,
"primary_key?": false
},
{
"default": "fragment(\"now()\")",
"size": null,
"type": "utc_datetime_usec",
"source": "updated_at",
"references": null,
"allow_nil?": false,
"generated?": false,
"primary_key?": false
}
],
"table": "users",
"hash": "B341A513EC6CF961202B8212C7C4E69600B5AE7A5669D8960EF59C9B41C16164",
"repo": "Elixir.Orcasite.Repo",
"identities": [
{
"name": "unique_email",
"keys": [
"email"
],
"index_name": "users_unique_email_index",
"base_filter": null
}
],
"schema": null,
"multitenancy": {
"global": null,
"strategy": null,
"attribute": null
},
"custom_indexes": [],
"base_filter": null,
"check_constraints": [],
"custom_statements": [],
"has_create_action": true
}
18 changes: 9 additions & 9 deletions ui/src/graphql/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -776,19 +776,19 @@ export type SubmitDetectionResult = {

export type User = {
__typename?: "User";
admin?: Maybe<Scalars["Boolean"]["output"]>;
admin: Scalars["Boolean"]["output"];
email: Scalars["String"]["output"];
firstName?: Maybe<Scalars["String"]["output"]>;
id: Scalars["ID"]["output"];
lastName?: Maybe<Scalars["String"]["output"]>;
moderator?: Maybe<Scalars["Boolean"]["output"]>;
moderator: Scalars["Boolean"]["output"];
};

export type UserFilterAdmin = {
eq?: InputMaybe<Scalars["Boolean"]["input"]>;
greaterThan?: InputMaybe<Scalars["Boolean"]["input"]>;
greaterThanOrEqual?: InputMaybe<Scalars["Boolean"]["input"]>;
in?: InputMaybe<Array<InputMaybe<Scalars["Boolean"]["input"]>>>;
in?: InputMaybe<Array<Scalars["Boolean"]["input"]>>;
isNil?: InputMaybe<Scalars["Boolean"]["input"]>;
lessThan?: InputMaybe<Scalars["Boolean"]["input"]>;
lessThanOrEqual?: InputMaybe<Scalars["Boolean"]["input"]>;
Expand Down Expand Up @@ -855,7 +855,7 @@ export type UserFilterModerator = {
eq?: InputMaybe<Scalars["Boolean"]["input"]>;
greaterThan?: InputMaybe<Scalars["Boolean"]["input"]>;
greaterThanOrEqual?: InputMaybe<Scalars["Boolean"]["input"]>;
in?: InputMaybe<Array<InputMaybe<Scalars["Boolean"]["input"]>>>;
in?: InputMaybe<Array<Scalars["Boolean"]["input"]>>;
isNil?: InputMaybe<Scalars["Boolean"]["input"]>;
lessThan?: InputMaybe<Scalars["Boolean"]["input"]>;
lessThanOrEqual?: InputMaybe<Scalars["Boolean"]["input"]>;
Expand Down Expand Up @@ -951,7 +951,7 @@ export type RegisterWithPasswordMutation = {
__typename?: "User";
id: string;
email: string;
admin?: boolean | null;
admin: boolean;
firstName?: string | null;
lastName?: string | null;
} | null;
Expand Down Expand Up @@ -999,7 +999,7 @@ export type ResetPasswordMutation = {
email: string;
firstName?: string | null;
lastName?: string | null;
admin?: boolean | null;
admin: boolean;
} | null;
} | null;
};
Expand Down Expand Up @@ -1042,7 +1042,7 @@ export type SignInWithPasswordMutation = {
__typename?: "User";
id: string;
email: string;
admin?: boolean | null;
admin: boolean;
firstName?: string | null;
lastName?: string | null;
} | null;
Expand Down Expand Up @@ -1125,8 +1125,8 @@ export type GetCurrentUserQuery = {
firstName?: string | null;
lastName?: string | null;
email: string;
admin?: boolean | null;
moderator?: boolean | null;
admin: boolean;
moderator: boolean;
} | null;
};

Expand Down
Loading