diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 000000000..f49ec5d7c --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,48 @@ +name: Create and publish a Docker image + +# Configures this workflow to run every time a tag is created. +on: + push: + tags: + - '*' + +# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. +jobs: + build-and-push-image: + runs-on: ubuntu-latest + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + # + steps: + - name: Checkout repository + uses: actions/checkout@v4 + # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. + # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. + - name: Build and push Docker image + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index a36e91559..4101960d2 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ vendor/ savedata/*/ *.exe *.lnk -*.bat \ No newline at end of file +*.bat +/docker/db-data \ No newline at end of file diff --git a/AUTHORS.md b/AUTHORS.md new file mode 100644 index 000000000..618d34264 --- /dev/null +++ b/AUTHORS.md @@ -0,0 +1,29 @@ +# List of AUTHORS who contributed over time to the Erupe project + +## Point of current development +The project is currently developed under https://github.com/ZeruLight/Erupe + +## History of development +Development of this project dates back to 2019, and was developed under various umbrellas over time: +* Cappuccino (Fist/Ando/Ellie42) (The Erupe Developers), 2019-2020 (https://github.com/Ellie42/Erupe / https://github.com/ricochhet/Erupe-Legacy) (Still active closed source) +* Einherjar Team, ????-2022 Feb (There is no git history for this period, this team's work was taken and used as a foundation for future repositories) +* Community Edition, 2022 (https://github.com/xl3lackout/Erupe) +* Zerulight, 2022-2023 (https://github.com/ZeruLight/Erupe) + +## Authorship of the code +Authorship is assigned for each commit within the git history, which is stored in these git repos: +* https://github.com/ZeruLight/Erupe +* https://github.com/Ellie42/Erupe +* https://github.com/ricochhet/Erupe-Legacy +* https://github.com/xl3lackout/Erupe + +Note there is a divergence between Ellie42s branch and xl3lackout where history has been lost. + +Unfortunately, we have no detailed information on the history of the Erupe pre-2022 +if somebody can provide information, please contact us, so that we can make this history available. + +## Exceptions with third-party libraries +The third-party libraries have their own way of addressing authorship and the authorship of commits importing/updating +a third-party library reflects who did the importing instead of who wrote the code within the commit. + +The Authors of third-party libraries are not explicitly mentioned, and usually is possible to obtain from the files belonging to the third-party libraries. \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..37015b19d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM golang:1.21-alpine3.19 + +ENV GO111MODULE=on + +WORKDIR /app/erupe + +COPY go.mod . +COPY go.sum . + +RUN go mod download + +COPY . . + +CMD [ "go", "run", "." ] \ No newline at end of file diff --git a/README.md b/README.md index 034e2a4ea..b9be1fb05 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,20 @@ If you want to modify or compile Erupe yourself, please read on. 3. Edit [config.json](./config.json) such that the database password matches your PostgreSQL setup. 4. Run `go build` or `go run .` to compile Erupe. +## Docker + +Please see the readme in [docker/README.md](./docker/README.md). At the moment this is only really good for quick installs and checking out development not for production. + +## Schemas + +We source control the following schemas: +- Initialisation Schemas: These initialise the application database to a clean install from a specific version. +- Update Schemas: These are update files they should be ran in order of version to get to the latest schema. +- Patch Schemas: These are for development and should be ran from the lastest available update schema or initial schema. These eventually get condensed into `Update Schemas` and then deleted when updated to a new version. +- Bundled Schemas: These are demo reference files to allow servers to be able to roll their own shops, distributions gachas and scenarios set ups. + +Note: Patch schemas are subject to change! You should only be using them if you are following along with development. + ## Resources - [Quest and Scenario Binary Files](https://files.catbox.moe/xf0l7w.7z) diff --git a/config.json b/config.json index 1e9e6486d..bffde254a 100644 --- a/config.json +++ b/config.json @@ -157,10 +157,10 @@ {"Name": "EXRenewing", "Enabled": true} ], "Database": { - "Host": "localhost", + "Host": "db", "Port": 5432, "User": "postgres", - "Password": "", + "Password": "password", "Database": "erupe" }, "Sign": { diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 000000000..3f45a12c0 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,66 @@ +# Docker for erupe + +## Building the container +Run the following from the route of the soruce folder. In this example we give it the tag of dev to seperate it from any other container verions. +```bash +docker build . -t erupe:dev +``` +## Running the container in isolation +This is just running the container. You can do volume mounts into the container for the `config.json` to tell it to communicate to a database. You will need to do this also for other folders such as `bin` and `savedata` +```bash +docker run erupe:dev +``` + +## Docker compose +Docker compose allows you to run multiple containers at once. The docker compose in this folder has 3 things set up. +- postgres +- pg admin (Admin interface to make db changes) +- erupe + +We automatically populate the database to the latest version on start. If you you are updating you will need to apply the new schemas manually. + +Before we get started you should make sure the database info matches whats in the docker compose file for the environment variables `POSTGRES_PASSWORD`,`POSTGRES_USER` and `POSTGRES_DB`. You can set the host to be the service name `db`. + +Here is a example of what you would put in the config.json if you was to leave the defaults. It is strongly recommended to change the password. +```txt +"Database": { + "Host": "db", + "Port": 5432, + "User": "postgres", + "Password": "password", + "Database": "erupe" + }, +``` + +Place this file within ./docker/config.json + +You will need to do the same for your bins place these in ./docker/bin + +# Setting up the web hosted materials +Clone the Severs repo into ./docker/Severs + +Make sure your hosts are pointing to where this is hosted + + + +## Turning off the server safely +```bash +docker-compose stop +``` + +## Turning off the server destructive +```bash +docker-compose down +``` +Make sure if you want to delete your data you delete the folders that persisted +- ./docker/savedata +- ./docker/db-data +## Turning on the server again +This boots the db pgadmin and the server in a detached state +```bash +docker-compose up -d +``` +if you want all the logs and you want it to be in an attached state +```bash +docker-compose up +``` diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 000000000..a610836ee --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,71 @@ +version: "3.9" +# 1. docker-compose up db pgadmin +# 2. Use pgadmin to restore db and also apply patch-schema +# 3. Configure the config.json example. in docker you can point to the service name for the database i.e db +# 4. In seperate terminal docker-compose up server +# 5. If all went well happy hunting! +services: + db: + image: postgres + environment: + # (Make sure these match config.json) + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=password + - POSTGRES_DB=erupe + ports: + - "5432:5432" + volumes: + - ./db-data/:/var/lib/postgresql/data/ + - ../schemas/:/schemas/ + - ./init/setup.sh:/docker-entrypoint-initdb.d/setup.sh + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 5s + timeout: 5s + retries: 5 + pgadmin: + image: dpage/pgadmin4 + restart: always + environment: + PGADMIN_DEFAULT_EMAIL: user@pgadmin.com + PGADMIN_DEFAULT_PASSWORD: password + ports: + - "5050:80" + depends_on: + db: + condition: service_healthy + server: + depends_on: + db: + condition: service_healthy + # If using prebuilt container change paths and config + build: + context: ../ + volumes: + - ./config.json:/app/erupe/config.json + - ./bin:/app/erupe/bin + - ./savedata:/app/erupe/savedata + ports: + # (Make sure these match config.json) + - "53312:53312" #Sign V1 + - "8080:8080" #Sign V2 + - "53310:53310" #Entrance + # Channels + - "54001:54001" + - "54002:54002" + - "54003:54003" + - "54004:54004" + - "54005:54005" + - "54006:54006" + - "54007:54007" + - "54008:54008" + web: + image: httpd:latest + container_name: my-apache-app + ports: + - '80:80' + volumes: + - ./Servers:/usr/local/apache2/htdocs + depends_on: + db: + condition: service_healthy \ No newline at end of file diff --git a/docker/init/setup.sh b/docker/init/setup.sh new file mode 100644 index 000000000..b84f83b4d --- /dev/null +++ b/docker/init/setup.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -e +echo "INIT!" +pg_restore --username="$POSTGRES_USER" --dbname="$POSTGRES_DB" --verbose /schemas/initialisation-schema/9.1-init.sql + + + +echo "Updating!" + +for file in /schemas/update-schema/* +do + psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -1 -f $file +done + + + +echo "Patching!" + +for file in /schemas/patch-schema/* +do + psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -1 -f $file +done \ No newline at end of file diff --git a/bundled-schema/DistributionDemo.sql b/schemas/bundled-schema/DistributionDemo.sql similarity index 100% rename from bundled-schema/DistributionDemo.sql rename to schemas/bundled-schema/DistributionDemo.sql diff --git a/bundled-schema/DivaShops.sql b/schemas/bundled-schema/DivaShops.sql similarity index 100% rename from bundled-schema/DivaShops.sql rename to schemas/bundled-schema/DivaShops.sql diff --git a/bundled-schema/EventQuests.sql b/schemas/bundled-schema/EventQuests.sql similarity index 100% rename from bundled-schema/EventQuests.sql rename to schemas/bundled-schema/EventQuests.sql diff --git a/bundled-schema/FPointItems.sql b/schemas/bundled-schema/FPointItems.sql similarity index 100% rename from bundled-schema/FPointItems.sql rename to schemas/bundled-schema/FPointItems.sql diff --git a/bundled-schema/FestaDefaults.sql b/schemas/bundled-schema/FestaDefaults.sql similarity index 100% rename from bundled-schema/FestaDefaults.sql rename to schemas/bundled-schema/FestaDefaults.sql diff --git a/bundled-schema/GachaDemo.sql b/schemas/bundled-schema/GachaDemo.sql similarity index 100% rename from bundled-schema/GachaDemo.sql rename to schemas/bundled-schema/GachaDemo.sql diff --git a/bundled-schema/NetcafeDefaults.sql b/schemas/bundled-schema/NetcafeDefaults.sql similarity index 100% rename from bundled-schema/NetcafeDefaults.sql rename to schemas/bundled-schema/NetcafeDefaults.sql diff --git a/bundled-schema/OtherShops.sql b/schemas/bundled-schema/OtherShops.sql similarity index 100% rename from bundled-schema/OtherShops.sql rename to schemas/bundled-schema/OtherShops.sql diff --git a/bundled-schema/RoadShopItems.sql b/schemas/bundled-schema/RoadShopItems.sql similarity index 100% rename from bundled-schema/RoadShopItems.sql rename to schemas/bundled-schema/RoadShopItems.sql diff --git a/bundled-schema/ScenarioDefaults.sql b/schemas/bundled-schema/ScenarioDefaults.sql similarity index 100% rename from bundled-schema/ScenarioDefaults.sql rename to schemas/bundled-schema/ScenarioDefaults.sql diff --git a/schemas/initialisation-schema/9.1-init.sql b/schemas/initialisation-schema/9.1-init.sql new file mode 100644 index 000000000..3ae0ca127 Binary files /dev/null and b/schemas/initialisation-schema/9.1-init.sql differ diff --git a/patch-schema/.gitkeep b/schemas/patch-schema/.gitkeep similarity index 100% rename from patch-schema/.gitkeep rename to schemas/patch-schema/.gitkeep diff --git a/patch-schema/00-psn-id.sql b/schemas/patch-schema/00-psn-id.sql similarity index 100% rename from patch-schema/00-psn-id.sql rename to schemas/patch-schema/00-psn-id.sql diff --git a/patch-schema/01-wiiu-key.sql b/schemas/patch-schema/01-wiiu-key.sql similarity index 100% rename from patch-schema/01-wiiu-key.sql rename to schemas/patch-schema/01-wiiu-key.sql diff --git a/patch-schema/02-tower.sql b/schemas/patch-schema/02-tower.sql similarity index 100% rename from patch-schema/02-tower.sql rename to schemas/patch-schema/02-tower.sql diff --git a/patch-schema/03-event_quests.sql b/schemas/patch-schema/03-event_quests.sql similarity index 100% rename from patch-schema/03-event_quests.sql rename to schemas/patch-schema/03-event_quests.sql diff --git a/patch-schema/04-trend-weapons.sql b/schemas/patch-schema/04-trend-weapons.sql similarity index 100% rename from patch-schema/04-trend-weapons.sql rename to schemas/patch-schema/04-trend-weapons.sql diff --git a/patch-schema/05-gacha-roll-name.sql b/schemas/patch-schema/05-gacha-roll-name.sql similarity index 100% rename from patch-schema/05-gacha-roll-name.sql rename to schemas/patch-schema/05-gacha-roll-name.sql diff --git a/patch-schema/06-goocoo-rename.sql b/schemas/patch-schema/06-goocoo-rename.sql similarity index 100% rename from patch-schema/06-goocoo-rename.sql rename to schemas/patch-schema/06-goocoo-rename.sql diff --git a/patch-schema/07-scenarios-counter.sql b/schemas/patch-schema/07-scenarios-counter.sql similarity index 100% rename from patch-schema/07-scenarios-counter.sql rename to schemas/patch-schema/07-scenarios-counter.sql diff --git a/patch-schema/08-kill-counts.sql b/schemas/patch-schema/08-kill-counts.sql similarity index 100% rename from patch-schema/08-kill-counts.sql rename to schemas/patch-schema/08-kill-counts.sql diff --git a/patch-schema/09-fix-guild-treasure.sql b/schemas/patch-schema/09-fix-guild-treasure.sql similarity index 100% rename from patch-schema/09-fix-guild-treasure.sql rename to schemas/patch-schema/09-fix-guild-treasure.sql diff --git a/patch-schema/10-rework-distributions.sql b/schemas/patch-schema/10-rework-distributions.sql similarity index 100% rename from patch-schema/10-rework-distributions.sql rename to schemas/patch-schema/10-rework-distributions.sql diff --git a/patch-schema/11-event-quest-flags.sql b/schemas/patch-schema/11-event-quest-flags.sql similarity index 100% rename from patch-schema/11-event-quest-flags.sql rename to schemas/patch-schema/11-event-quest-flags.sql diff --git a/patch-schema/12-event_quest_cycling.sql b/schemas/patch-schema/12-event_quest_cycling.sql similarity index 100% rename from patch-schema/12-event_quest_cycling.sql rename to schemas/patch-schema/12-event_quest_cycling.sql diff --git a/patch-schema/13-festa-trial-votes.sql b/schemas/patch-schema/13-festa-trial-votes.sql similarity index 100% rename from patch-schema/13-festa-trial-votes.sql rename to schemas/patch-schema/13-festa-trial-votes.sql diff --git a/patch-schema/14-fix-fpoint-trades.sql b/schemas/patch-schema/14-fix-fpoint-trades.sql similarity index 100% rename from patch-schema/14-fix-fpoint-trades.sql rename to schemas/patch-schema/14-fix-fpoint-trades.sql diff --git a/patch-schema/15-reset-goocoos.sql b/schemas/patch-schema/15-reset-goocoos.sql similarity index 100% rename from patch-schema/15-reset-goocoos.sql rename to schemas/patch-schema/15-reset-goocoos.sql diff --git a/patch-schema/16-discord-password-resets.sql b/schemas/patch-schema/16-discord-password-resets.sql similarity index 100% rename from patch-schema/16-discord-password-resets.sql rename to schemas/patch-schema/16-discord-password-resets.sql diff --git a/patch-schema/op-accounts.sql b/schemas/patch-schema/op-accounts.sql similarity index 100% rename from patch-schema/op-accounts.sql rename to schemas/patch-schema/op-accounts.sql diff --git a/patch-schema/psn-link.sql b/schemas/patch-schema/psn-link.sql similarity index 100% rename from patch-schema/psn-link.sql rename to schemas/patch-schema/psn-link.sql diff --git a/schemas/update-schema/9.2-update.sql b/schemas/update-schema/9.2-update.sql new file mode 100644 index 000000000..e7dbf699b --- /dev/null +++ b/schemas/update-schema/9.2-update.sql @@ -0,0 +1,241 @@ +BEGIN; + +DROP TABLE IF EXISTS public.fpoint_items; + +CREATE TABLE IF NOT EXISTS public.fpoint_items ( + id serial PRIMARY KEY, + item_type integer, + item_id integer, + quantity integer, + fpoints integer, + trade_type integer +); + +ALTER TABLE IF EXISTS public.characters ADD bonus_quests INT NOT NULL DEFAULT 0; + +ALTER TABLE IF EXISTS public.characters ADD daily_quests INT NOT NULL DEFAULT 0; + +ALTER TABLE IF EXISTS public.characters ADD promo_points INT NOT NULL DEFAULT 0; + +ALTER TABLE IF EXISTS public.guild_characters ADD rp_today INT DEFAULT 0; + +ALTER TABLE IF EXISTS public.guild_characters ADD rp_yesterday INT DEFAULT 0; + +UPDATE public.characters SET savemercenary = NULL; + +ALTER TABLE IF EXISTS public.characters ADD rasta_id INT; + +ALTER TABLE IF EXISTS public.characters ADD pact_id INT; + +ALTER TABLE IF EXISTS public.characters ADD stampcard INT NOT NULL DEFAULT 0; + +ALTER TABLE IF EXISTS public.characters DROP COLUMN IF EXISTS gacha_prem; + +ALTER TABLE IF EXISTS public.characters DROP COLUMN IF EXISTS gacha_trial; + +ALTER TABLE IF EXISTS public.characters DROP COLUMN IF EXISTS frontier_points; + +ALTER TABLE IF EXISTS public.users ADD IF NOT EXISTS gacha_premium INT; + +ALTER TABLE IF EXISTS public.users ADD IF NOT EXISTS gacha_trial INT; + +ALTER TABLE IF EXISTS public.users ADD IF NOT EXISTS frontier_points INT; + +DROP TABLE IF EXISTS public.gacha_shop; + +CREATE TABLE IF NOT EXISTS public.gacha_shop ( + id SERIAL PRIMARY KEY, + min_gr INTEGER, + min_hr INTEGER, + name TEXT, + url_banner TEXT, + url_feature TEXT, + url_thumbnail TEXT, + wide BOOLEAN, + recommended BOOLEAN, + gacha_type INTEGER, + hidden BOOLEAN +); + +DROP TABLE IF EXISTS public.gacha_shop_items; + +CREATE TABLE IF NOT EXISTS public.gacha_entries ( + id SERIAL PRIMARY KEY, + gacha_id INTEGER, + entry_type INTEGER, + item_type INTEGER, + item_number INTEGER, + item_quantity INTEGER, + weight INTEGER, + rarity INTEGER, + rolls INTEGER, + frontier_points INTEGER, + daily_limit INTEGER +); + +CREATE TABLE IF NOT EXISTS public.gacha_items ( + id SERIAL PRIMARY KEY, + entry_id INTEGER, + item_type INTEGER, + item_id INTEGER, + quantity INTEGER +); + +DROP TABLE IF EXISTS public.stepup_state; + +CREATE TABLE IF NOT EXISTS public.gacha_stepup ( + gacha_id INTEGER, + step INTEGER, + character_id INTEGER +); + +DROP TABLE IF EXISTS public.lucky_box_state; + +CREATE TABLE IF NOT EXISTS public.gacha_box ( + gacha_id INTEGER, + entry_id INTEGER, + character_id INTEGER +); + +DROP TABLE IF EXISTS public.login_boost_state; + +CREATE TABLE IF NOT EXISTS public.login_boost ( + char_id INTEGER, + week_req INTEGER, + expiration TIMESTAMP WITH TIME ZONE, + reset TIMESTAMP WITH TIME ZONE +); + +ALTER TABLE IF EXISTS public.characters ADD COLUMN mezfes BYTEA; + +ALTER TABLE IF EXISTS public.characters ALTER COLUMN daily_time TYPE TIMESTAMP WITH TIME ZONE; + +ALTER TABLE IF EXISTS public.characters ALTER COLUMN guild_post_checked TYPE TIMESTAMP WITH TIME ZONE; + +ALTER TABLE IF EXISTS public.characters ALTER COLUMN boost_time TYPE TIMESTAMP WITH TIME ZONE; + +ALTER TABLE IF EXISTS public.characters ADD COLUMN IF NOT EXISTS cafe_reset TIMESTAMP WITHOUT TIME ZONE; + +ALTER TABLE IF EXISTS public.characters ALTER COLUMN cafe_reset TYPE TIMESTAMP WITH TIME ZONE; + +ALTER TABLE IF EXISTS public.distribution ALTER COLUMN deadline TYPE TIMESTAMP WITH TIME ZONE; + +ALTER TABLE IF EXISTS public.events ALTER COLUMN start_time TYPE TIMESTAMP WITH TIME ZONE; + +ALTER TABLE IF EXISTS public.feature_weapon ALTER COLUMN start_time TYPE TIMESTAMP WITH TIME ZONE; + +CREATE TABLE IF NOT EXISTS public.feature_weapon +( + start_time TIMESTAMP WITH TIME ZONE NOT NULL, + featured INTEGER NOT NULL +); + +ALTER TABLE IF EXISTS public.guild_alliances ALTER COLUMN created_at TYPE TIMESTAMP WITH TIME ZONE; + +ALTER TABLE IF EXISTS public.guild_applications ALTER COLUMN created_at TYPE TIMESTAMP WITH TIME ZONE; + +ALTER TABLE IF EXISTS public.guild_characters ALTER COLUMN joined_at TYPE TIMESTAMP WITH TIME ZONE; + +ALTER TABLE IF EXISTS public.guild_posts ALTER COLUMN created_at TYPE TIMESTAMP WITH TIME ZONE; + +ALTER TABLE IF EXISTS public.characters ALTER COLUMN daily_time TYPE TIMESTAMP WITH TIME ZONE; + +ALTER TABLE IF EXISTS public.guilds ALTER COLUMN created_at TYPE TIMESTAMP WITH TIME ZONE; + +ALTER TABLE IF EXISTS public.mail ALTER COLUMN created_at TYPE TIMESTAMP WITH TIME ZONE; + +ALTER TABLE IF EXISTS public.stamps ALTER COLUMN hl_next TYPE TIMESTAMP WITH TIME ZONE; + +ALTER TABLE IF EXISTS public.stamps ALTER COLUMN ex_next TYPE TIMESTAMP WITH TIME ZONE; + +ALTER TABLE IF EXISTS public.titles ALTER COLUMN unlocked_at TYPE TIMESTAMP WITH TIME ZONE; + +ALTER TABLE IF EXISTS public.titles ALTER COLUMN updated_at TYPE TIMESTAMP WITH TIME ZONE; + +ALTER TABLE IF EXISTS public.users ALTER COLUMN last_login TYPE TIMESTAMP WITH TIME ZONE; + +ALTER TABLE IF EXISTS public.users ALTER COLUMN return_expires TYPE TIMESTAMP WITH TIME ZONE; + +ALTER TABLE IF EXISTS public.guild_meals DROP COLUMN IF EXISTS expires; + +ALTER TABLE IF EXISTS public.guild_meals ADD COLUMN IF NOT EXISTS created_at TIMESTAMP WITH TIME ZONE; + +DROP TABLE IF EXISTS public.account_ban; + +DROP TABLE IF EXISTS public.account_history; + +DROP TABLE IF EXISTS public.account_moderation; + +DROP TABLE IF EXISTS public.account_sub; + +DROP TABLE IF EXISTS public.history; + +DROP TABLE IF EXISTS public.questlists; + +DROP TABLE IF EXISTS public.schema_migrations; + +DROP TABLE IF EXISTS public.user_binaries; + +DROP PROCEDURE IF EXISTS raviinit; + +DROP PROCEDURE IF EXISTS ravireset; + +ALTER TABLE IF EXISTS public.normal_shop_items RENAME TO shop_items; + +ALTER TABLE IF EXISTS public.shop_items RENAME COLUMN shoptype TO shop_type; + +ALTER TABLE IF EXISTS public.shop_items RENAME COLUMN shopid TO shop_id; + +ALTER TABLE IF EXISTS public.shop_items RENAME COLUMN itemhash TO id; + +ALTER TABLE IF EXISTS public.shop_items RENAME COLUMN itemid TO item_id; + +ALTER TABLE IF EXISTS public.shop_items ALTER COLUMN points TYPE integer; + +ALTER TABLE IF EXISTS public.shop_items RENAME COLUMN points TO cost; + +ALTER TABLE IF EXISTS public.shop_items RENAME COLUMN tradequantity TO quantity; + +ALTER TABLE IF EXISTS public.shop_items RENAME COLUMN rankreqlow TO min_hr; + +ALTER TABLE IF EXISTS public.shop_items RENAME COLUMN rankreqhigh TO min_sr; + +ALTER TABLE IF EXISTS public.shop_items RENAME COLUMN rankreqg TO min_gr; + +ALTER TABLE IF EXISTS public.shop_items RENAME COLUMN storelevelreq TO store_level; + +ALTER TABLE IF EXISTS public.shop_items RENAME COLUMN maximumquantity TO max_quantity; + +ALTER TABLE IF EXISTS public.shop_items DROP COLUMN IF EXISTS boughtquantity; + +ALTER TABLE IF EXISTS public.shop_items RENAME COLUMN roadfloorsrequired TO road_floors; + +ALTER TABLE IF EXISTS public.shop_items RENAME COLUMN weeklyfataliskills TO road_fatalis; + +ALTER TABLE public.shop_items RENAME CONSTRAINT normal_shop_items_pkey TO shop_items_pkey; + +ALTER TABLE IF EXISTS public.shop_items DROP CONSTRAINT IF EXISTS normal_shop_items_itemhash_key; + +CREATE SEQUENCE IF NOT EXISTS public.shop_items_id_seq; + +ALTER SEQUENCE IF EXISTS public.shop_items_id_seq OWNER TO postgres; + +ALTER TABLE IF EXISTS public.shop_items ALTER COLUMN id SET DEFAULT nextval('shop_items_id_seq'::regclass); + +ALTER SEQUENCE IF EXISTS public.shop_items_id_seq OWNED BY shop_items.id; + +SELECT setval('shop_items_id_seq', (SELECT MAX(id) FROM public.shop_items)); + +DROP TABLE IF EXISTS public.shop_item_state; + +CREATE TABLE IF NOT EXISTS public.shop_items_bought ( + character_id INTEGER, + shop_item_id INTEGER, + bought INTEGER +); + +UPDATE users SET rights = rights-2; + +ALTER TABLE IF EXISTS public.users ALTER COLUMN rights SET DEFAULT 12; + +END; \ No newline at end of file