mirror of
https://github.com/Sheldan/gw2-tools.git
synced 2026-04-08 16:07:34 +00:00
initial commit of functioning opening tracking
This commit is contained in:
62
gw2-tools-backend/database/pom.xml
Normal file
62
gw2-tools-backend/database/pom.xml
Normal file
@@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>dev.sheldan.gw2.tools</groupId>
|
||||
<artifactId>gw2-tools</artifactId>
|
||||
<version>0.0.9-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>database</artifactId>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src/main/kotlin</sourceDirectory>
|
||||
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-test-junit5</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
2
gw2-tools-backend/database/src/main/docker/Dockerfile
Normal file
2
gw2-tools-backend/database/src/main/docker/Dockerfile
Normal file
@@ -0,0 +1,2 @@
|
||||
FROM liquibase/liquibase:4.25.1-alpine
|
||||
ADD resources/changeLog/ /liquibase/
|
||||
@@ -0,0 +1,27 @@
|
||||
package dev.sheldan.gw2.tools.entity
|
||||
|
||||
import jakarta.persistence.*
|
||||
|
||||
@Entity(name = "currency")
|
||||
class Currency(@Column(name="name", nullable = false)
|
||||
val name: String,
|
||||
|
||||
@Column(name="description")
|
||||
val description: String,
|
||||
|
||||
@Column(name="icon_url", nullable = false)
|
||||
val iconUrl: String,
|
||||
|
||||
@OneToMany(
|
||||
fetch = FetchType.LAZY,
|
||||
cascade = [CascadeType.PERSIST, CascadeType.MERGE],
|
||||
mappedBy = "currency"
|
||||
)
|
||||
private var openings: List<OpeningCurrency>? = null,
|
||||
|
||||
@Id
|
||||
@Column(name="id", nullable = false)
|
||||
val id: Int) {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package dev.sheldan.gw2.tools.entity
|
||||
|
||||
import jakarta.persistence.*
|
||||
|
||||
@Entity(name = "item")
|
||||
class Item(@Column(name="name", nullable = false)
|
||||
val name: String,
|
||||
|
||||
@Column(name="description")
|
||||
val description: String,
|
||||
|
||||
@Column(name="icon_url", nullable = false)
|
||||
val iconUrl: String,
|
||||
|
||||
@Column(name="type", nullable = false)
|
||||
val type: String,
|
||||
|
||||
@Column(name="rarity", nullable = false)
|
||||
val rarity: String,
|
||||
|
||||
@OneToMany(cascade = [CascadeType.MERGE, CascadeType.PERSIST], orphanRemoval = true, fetch = FetchType.LAZY, mappedBy = "item")
|
||||
var submissionTemplates: List<SubmissionTemplate>? = null,
|
||||
|
||||
@OneToMany(
|
||||
fetch = FetchType.LAZY,
|
||||
cascade = [CascadeType.PERSIST, CascadeType.MERGE],
|
||||
mappedBy = "item"
|
||||
)
|
||||
private var openings: List<OpeningItem>? = null,
|
||||
|
||||
@Id
|
||||
@Column(name="id", nullable = false)
|
||||
val id: Int) {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package dev.sheldan.gw2.tools.entity
|
||||
|
||||
import jakarta.persistence.*
|
||||
import java.time.Instant
|
||||
|
||||
@Entity(name = "opening")
|
||||
class Opening(
|
||||
@ManyToOne(fetch = FetchType.LAZY, optional = false)
|
||||
@JoinColumn(name = "user_id", referencedColumnName = "id")
|
||||
val user: User,
|
||||
@OneToMany(cascade = [CascadeType.MERGE, CascadeType.PERSIST], orphanRemoval = true, fetch = FetchType.LAZY, mappedBy = "opening")
|
||||
var currencies: List<OpeningCurrency>? = null,
|
||||
@OneToMany(cascade = [CascadeType.MERGE, CascadeType.PERSIST], orphanRemoval = true, fetch = FetchType.LAZY, mappedBy = "opening")
|
||||
var items: List<OpeningItem>? = null,
|
||||
@Column(name = "description")
|
||||
var description: String?=null,
|
||||
@Column(name = "created", insertable = false, updatable = false)
|
||||
var creationDate: Instant?=null,
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
val id: Int?=null
|
||||
) {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package dev.sheldan.gw2.tools.entity
|
||||
|
||||
import jakarta.persistence.*
|
||||
|
||||
@Entity(name = "opening_currency")
|
||||
class OpeningCurrency(
|
||||
@ManyToOne(cascade = [CascadeType.PERSIST, CascadeType.MERGE])
|
||||
@JoinColumn(name = "currency_id", nullable = false)
|
||||
val currency: Currency,
|
||||
@ManyToOne(cascade = [CascadeType.PERSIST, CascadeType.MERGE])
|
||||
@JoinColumn(name = "opening_id", nullable = false)
|
||||
val opening: Opening,
|
||||
@Column(name = "amount")
|
||||
val amount: Int,
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
val id: Int?=null
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package dev.sheldan.gw2.tools.entity
|
||||
|
||||
import jakarta.persistence.*
|
||||
|
||||
@Entity(name = "opening_item")
|
||||
class OpeningItem(
|
||||
@ManyToOne(cascade = [CascadeType.PERSIST, CascadeType.MERGE])
|
||||
@JoinColumn(name = "item_id", nullable = false)
|
||||
val item: Item,
|
||||
@ManyToOne(cascade = [CascadeType.PERSIST, CascadeType.MERGE])
|
||||
@JoinColumn(name = "opening_id", nullable = false)
|
||||
val opening: Opening,
|
||||
@Column(name = "count")
|
||||
val count: Int,
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
val id: Int?=null
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package dev.sheldan.gw2.tools.entity
|
||||
|
||||
import jakarta.persistence.*
|
||||
|
||||
@Entity(name = "submission_template")
|
||||
class SubmissionTemplate(
|
||||
@ManyToOne(cascade = [CascadeType.PERSIST, CascadeType.MERGE])
|
||||
@JoinColumn(name = "item_id", nullable = false)
|
||||
val item: Item,
|
||||
@Column(name = "template_text")
|
||||
val templateText: String,
|
||||
@Column(name = "name")
|
||||
val name: String,
|
||||
@Column(name = "description")
|
||||
val description: String,
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
val id: Int?=null
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package dev.sheldan.gw2.tools.entity
|
||||
|
||||
import jakarta.persistence.Column
|
||||
import jakarta.persistence.Entity
|
||||
import jakarta.persistence.Id
|
||||
|
||||
@Entity(name = "gw2_user")
|
||||
class User( @Id
|
||||
@Column(name="id", nullable = false)
|
||||
val id: String) {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package dev.sheldan.gw2.tools.repo
|
||||
|
||||
import dev.sheldan.gw2.tools.entity.Currency
|
||||
import org.springframework.data.repository.CrudRepository
|
||||
|
||||
interface CurrencyRepository : CrudRepository<Currency, Int> {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package dev.sheldan.gw2.tools.repo
|
||||
|
||||
import dev.sheldan.gw2.tools.entity.Item
|
||||
import org.springframework.data.repository.CrudRepository
|
||||
|
||||
interface ItemRepository : CrudRepository<Item, Int> {
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package dev.sheldan.gw2.tools.repo
|
||||
|
||||
import dev.sheldan.gw2.tools.entity.Opening
|
||||
import dev.sheldan.gw2.tools.entity.User
|
||||
import org.springframework.data.repository.CrudRepository
|
||||
|
||||
interface OpeningRepository : CrudRepository<Opening, Int> {
|
||||
fun getAllByUser(user: User): List<Opening>
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package dev.sheldan.gw2.tools.repo
|
||||
|
||||
import dev.sheldan.gw2.tools.entity.Item
|
||||
import dev.sheldan.gw2.tools.entity.SubmissionTemplate
|
||||
import org.springframework.data.repository.CrudRepository
|
||||
|
||||
interface SubmissionTemplateRepository : CrudRepository<SubmissionTemplate, Int> {
|
||||
fun getSubmissionTemplateByItem(item: Item): List<SubmissionTemplate>
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package dev.sheldan.gw2.tools.repo
|
||||
|
||||
import dev.sheldan.gw2.tools.entity.User
|
||||
import org.springframework.data.repository.CrudRepository
|
||||
|
||||
interface UserRepository : CrudRepository<User, String> {
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package dev.sheldan.gw2.tools.service
|
||||
|
||||
import dev.sheldan.gw2.tools.entity.Currency
|
||||
import dev.sheldan.gw2.tools.repo.CurrencyRepository
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Component
|
||||
class CurrencyManagement(val currencyRepository: CurrencyRepository) {
|
||||
fun getCurrencies(currencyIds: List<Int>): List<Currency> {
|
||||
return currencyRepository.findAllById(currencyIds).toList()
|
||||
}
|
||||
|
||||
fun getCurrenciesAsMap(currencyIds: List<Int>): Map<Int, Currency> {
|
||||
return getCurrencies(currencyIds).associateBy { it.id }
|
||||
}
|
||||
|
||||
fun getCurrencies() : List<Currency> {
|
||||
return currencyRepository.findAll().toList()
|
||||
}
|
||||
|
||||
fun createAndSaveCurrency(id: Int, name: String, description: String, iconUrl: String): Currency {
|
||||
val currency = createCurrency(id, name, description, iconUrl)
|
||||
return currencyRepository.save(currency)
|
||||
}
|
||||
|
||||
fun createCurrency(id: Int, name: String, description: String, iconUrl: String): Currency {
|
||||
return Currency(name, description, iconUrl, null, id)
|
||||
}
|
||||
|
||||
fun saveCurrency(currency: Currency): Currency {
|
||||
return currencyRepository.save(currency)
|
||||
}
|
||||
|
||||
fun saveCurrencies(currencies: List<Currency>) {
|
||||
currencyRepository.saveAll(currencies)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package dev.sheldan.gw2.tools.service
|
||||
|
||||
import dev.sheldan.gw2.tools.entity.Item
|
||||
import dev.sheldan.gw2.tools.repo.ItemRepository
|
||||
import org.springframework.data.repository.findByIdOrNull
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Component
|
||||
class ItemManagement(val itemRepository: ItemRepository) {
|
||||
fun getItems(itemIds: List<Int>) : List<Item> {
|
||||
return itemRepository.findAllById(itemIds).toList()
|
||||
}
|
||||
|
||||
fun getItem(itemId: Int) : Item? {
|
||||
return itemRepository.findByIdOrNull(itemId)
|
||||
}
|
||||
|
||||
fun getItemsAsMap(itemIds: List<Int>) : Map<Int, Item> {
|
||||
return getItems(itemIds).associateBy { it.id }
|
||||
}
|
||||
|
||||
fun getItems() : List<Item> {
|
||||
return itemRepository.findAll().toList()
|
||||
}
|
||||
|
||||
fun createItem(id: Int, name: String, description: String, iconUrl: String, type: String, rarity: String): Item {
|
||||
return Item(name, description, iconUrl, type, rarity, null, null, id)
|
||||
}
|
||||
|
||||
fun createAndSaveItem(id: Int, name: String, description: String, iconUrl: String, type: String, rarity: String): Item {
|
||||
val item = createItem(id, name, description, iconUrl, type, rarity)
|
||||
return saveItem(item)
|
||||
}
|
||||
|
||||
fun saveItems(items: List<Item>) {
|
||||
itemRepository.saveAll(items)
|
||||
}
|
||||
|
||||
fun saveItem(item: Item): Item {
|
||||
return itemRepository.save(item)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package dev.sheldan.gw2.tools.service
|
||||
|
||||
import dev.sheldan.gw2.tools.entity.*
|
||||
import dev.sheldan.gw2.tools.entity.Currency
|
||||
import dev.sheldan.gw2.tools.repo.OpeningRepository
|
||||
import org.springframework.stereotype.Component
|
||||
import java.util.*
|
||||
|
||||
@Component
|
||||
class OpeningManagement(
|
||||
val openingRepository: OpeningRepository
|
||||
) {
|
||||
fun createOpening(user: User, items: Map<Item, Int>, currencies: Map<Currency, Int>, description: String?){
|
||||
val opening = Opening(user, description = description)
|
||||
val openingItems: List<OpeningItem> = items.map { OpeningItem(it.key, opening, it.value) }
|
||||
val openingCurrencies: List<OpeningCurrency> = currencies.map { OpeningCurrency(it.key, opening, it.value) }
|
||||
opening.currencies = openingCurrencies
|
||||
opening.items = openingItems
|
||||
openingRepository.save(opening)
|
||||
}
|
||||
|
||||
fun getOpeningsByUser(user: User): List<Opening> {
|
||||
return openingRepository.getAllByUser(user)
|
||||
}
|
||||
|
||||
fun getAllOpenings(): List<Opening> {
|
||||
return openingRepository.findAll().toList()
|
||||
}
|
||||
|
||||
fun getOpening(id: Int): Optional<Opening> {
|
||||
return openingRepository.findById(id)
|
||||
}
|
||||
|
||||
fun deleteOpening(opening: Opening) {
|
||||
openingRepository.delete(opening)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package dev.sheldan.gw2.tools.service
|
||||
|
||||
import dev.sheldan.gw2.tools.entity.Item
|
||||
import dev.sheldan.gw2.tools.entity.SubmissionTemplate
|
||||
import dev.sheldan.gw2.tools.repo.SubmissionTemplateRepository
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Component
|
||||
class SubmissionTemplateManagement(
|
||||
val submissionTemplateRepository: SubmissionTemplateRepository
|
||||
) {
|
||||
|
||||
fun getSubmissionTemplatesForItem(item: Item): List<SubmissionTemplate> {
|
||||
return submissionTemplateRepository.getSubmissionTemplateByItem(item)
|
||||
}
|
||||
|
||||
fun getAllSubmissionTemplates(): List<SubmissionTemplate> {
|
||||
return submissionTemplateRepository.findAll().toList()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package dev.sheldan.gw2.tools.service
|
||||
|
||||
import dev.sheldan.gw2.tools.entity.User
|
||||
import dev.sheldan.gw2.tools.repo.UserRepository
|
||||
import org.springframework.data.repository.findByIdOrNull
|
||||
import org.springframework.stereotype.Component
|
||||
import java.security.MessageDigest
|
||||
|
||||
@Component
|
||||
class UserManagement(val userRepository: UserRepository) {
|
||||
fun getUser(id: String): User? {
|
||||
return userRepository.findByIdOrNull(id)
|
||||
}
|
||||
|
||||
fun getOrCreateUser(token: String): User {
|
||||
val userId = createUserId(token)
|
||||
val possibleUser = getUser(userId)
|
||||
return possibleUser ?: createUser(userId)
|
||||
}
|
||||
|
||||
fun createUserWithId(id: String): User {
|
||||
val userObj = User(id)
|
||||
return userRepository.save(userObj)
|
||||
}
|
||||
|
||||
fun createUser(token: String): User {
|
||||
val hashed = createUserId(token)
|
||||
val userObj = User(hashed)
|
||||
return userRepository.save(userObj)
|
||||
}
|
||||
|
||||
private fun createUserId(token: String): String {
|
||||
val md = MessageDigest.getInstance("SHA-256")
|
||||
val digest = md.digest(token.toByteArray())
|
||||
val hashed = digest.fold("") { str, it -> str + "%02x".format(it) }
|
||||
return hashed
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.25.xsd">
|
||||
<include file="tables/tables.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.25.xsd">
|
||||
|
||||
<changeSet author="Sheldan" id="currency-table">
|
||||
<createTable tableName="currency">
|
||||
<column name="id" type="INTEGER">
|
||||
<constraints nullable="false" primaryKey="true"/>
|
||||
</column>
|
||||
<column name="name" type="VARCHAR(64)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="description" type="VARCHAR(255)">
|
||||
<constraints nullable="true"/>
|
||||
</column>
|
||||
<column name="icon_url" type="VARCHAR(255)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
|
||||
</createTable>
|
||||
<sql>
|
||||
DROP TRIGGER IF EXISTS currency_update_trigger ON currency;
|
||||
CREATE TRIGGER currency_update_trigger BEFORE UPDATE ON currency FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
|
||||
</sql>
|
||||
<sql>
|
||||
DROP TRIGGER IF EXISTS currency_insert_trigger ON currency;
|
||||
CREATE TRIGGER currency_insert_trigger BEFORE INSERT ON currency FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
|
||||
</sql>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.25.xsd">
|
||||
|
||||
<changeSet author="Sheldan" id="item-table">
|
||||
<createTable tableName="item">
|
||||
<column name="id" type="INTEGER">
|
||||
<constraints nullable="false" primaryKey="true"/>
|
||||
</column>
|
||||
<column name="name" type="VARCHAR(128)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="description" type="VARCHAR(1024)">
|
||||
<constraints nullable="true"/>
|
||||
</column>
|
||||
<column name="icon_url" type="VARCHAR(255)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="type" type="VARCHAR(64)">
|
||||
<constraints nullable="true"/>
|
||||
</column>
|
||||
<column name="rarity" type="VARCHAR(32)">
|
||||
<constraints nullable="true"/>
|
||||
</column>
|
||||
<column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
|
||||
</createTable>
|
||||
<sql>
|
||||
ALTER TABLE item ADD CONSTRAINT check_item_rarity CHECK (rarity IN ('JUNK', 'BASIC', 'FINE', 'MASTERWORK', 'RARE', 'EXOTIC', 'ASCENDED', 'LEGENDARY'));
|
||||
ALTER TABLE item ADD CONSTRAINT check_item_type CHECK (type IN ('CONTAINER', 'ARMOR', 'BACK', 'BAG', 'CONSUMABLE', 'CRAFTING_MATERIAL', 'GATHERING', 'GIZMO', 'JADE_TECH_MODULE', 'KEY', 'MINI_PET', 'POWER_CORE', 'TOOL', 'TRAIT', 'TRINKET', 'TROPHY', 'UPGRADE_COMPONENT', 'WEAPON', 'RELIC'));
|
||||
</sql>
|
||||
<sql>
|
||||
DROP TRIGGER IF EXISTS item_update_trigger ON item;
|
||||
CREATE TRIGGER item_update_trigger BEFORE UPDATE ON item FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
|
||||
</sql>
|
||||
<sql>
|
||||
DROP TRIGGER IF EXISTS item_insert_trigger ON item;
|
||||
CREATE TRIGGER item_insert_trigger BEFORE INSERT ON item FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
|
||||
</sql>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,82 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.25.xsd">
|
||||
|
||||
<changeSet author="Sheldan" id="opening-table">
|
||||
<createTable tableName="opening">
|
||||
<column autoIncrement="true" name="id" type="BIGINT">
|
||||
<constraints nullable="false" primaryKey="true" primaryKeyName="pk_opening"/>
|
||||
</column>
|
||||
<column name="user_id" type="VARCHAR(255)">
|
||||
<constraints nullable="false" />
|
||||
</column>
|
||||
<column name="description" type="VARCHAR(1024)"/>
|
||||
<column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
|
||||
</createTable>
|
||||
<addForeignKeyConstraint baseColumnNames="user_id" baseTableName="opening" constraintName="fk_opening_user" deferrable="false"
|
||||
initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id"
|
||||
referencedTableName="gw2_user" validate="true"/>
|
||||
<sql>
|
||||
DROP TRIGGER IF EXISTS opening_update_trigger ON opening;
|
||||
CREATE TRIGGER opening_update_trigger BEFORE UPDATE ON opening FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
|
||||
</sql>
|
||||
<sql>
|
||||
DROP TRIGGER IF EXISTS opening_insert_trigger ON opening;
|
||||
CREATE TRIGGER opening_insert_trigger BEFORE INSERT ON opening FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
|
||||
</sql>
|
||||
</changeSet>
|
||||
<changeSet author="Sheldan" id="opening_currency-table">
|
||||
<createTable tableName="opening_currency">
|
||||
<column autoIncrement="true" name="id" type="BIGINT">
|
||||
<constraints nullable="false" primaryKey="true" primaryKeyName="pk_opening_currency"/>
|
||||
</column>
|
||||
<column name="opening_id" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="currency_id" type="INT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="amount" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
</createTable>
|
||||
<addForeignKeyConstraint baseColumnNames="opening_id" baseTableName="opening_currency"
|
||||
constraintName="fk_opening_currency_opening" deferrable="false"
|
||||
initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION"
|
||||
referencedColumnNames="id" referencedTableName="opening"
|
||||
validate="true"/>
|
||||
<addForeignKeyConstraint baseColumnNames="currency_id" baseTableName="opening_currency"
|
||||
constraintName="fk_opening_currency_currency" deferrable="false"
|
||||
initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id"
|
||||
referencedTableName="currency" validate="true"/>
|
||||
</changeSet>
|
||||
<changeSet author="Sheldan" id="opening_item-table">
|
||||
<createTable tableName="opening_item">
|
||||
<column autoIncrement="true" name="id" type="BIGINT">
|
||||
<constraints nullable="false" primaryKey="true" primaryKeyName="pk_opening_item"/>
|
||||
</column>
|
||||
<column name="opening_id" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="item_id" type="INT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="count" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
</createTable>
|
||||
<addForeignKeyConstraint baseColumnNames="opening_id" baseTableName="opening_item"
|
||||
constraintName="fk_opening_item_opening" deferrable="false"
|
||||
initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION"
|
||||
referencedColumnNames="id" referencedTableName="opening"
|
||||
validate="true"/>
|
||||
<addForeignKeyConstraint baseColumnNames="item_id" baseTableName="opening_item"
|
||||
constraintName="fk_opening_item_item" deferrable="false"
|
||||
initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id"
|
||||
referencedTableName="item" validate="true"/>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,8 @@
|
||||
CREATE OR REPLACE FUNCTION insert_trigger_procedure() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
BEGIN
|
||||
NEW.created := CURRENT_TIMESTAMP;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$;
|
||||
@@ -0,0 +1,8 @@
|
||||
CREATE OR REPLACE FUNCTION update_trigger_procedure() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
BEGIN
|
||||
NEW.updated := CURRENT_TIMESTAMP;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$;
|
||||
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.25.xsd">
|
||||
|
||||
<changeSet author="Sheldan" id="submission_template-table">
|
||||
<createTable tableName="submission_template">
|
||||
<column autoIncrement="true" name="id" type="BIGINT">
|
||||
<constraints nullable="false" primaryKey="true" primaryKeyName="pk_submission_template"/>
|
||||
</column>
|
||||
<column name="item_id" type="INTEGER">
|
||||
<constraints nullable="false" />
|
||||
</column>
|
||||
<column name="description" type="VARCHAR(1024)"/>
|
||||
<column name="template_text" type="VARCHAR(2048)"/>
|
||||
<column name="name" type="VARCHAR(128)"/>
|
||||
<column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
|
||||
</createTable>
|
||||
<addForeignKeyConstraint baseColumnNames="item_id" baseTableName="submission_template" constraintName="fk_submission_template_item" deferrable="false"
|
||||
initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id"
|
||||
referencedTableName="item" validate="true"/>
|
||||
<sql>
|
||||
DROP TRIGGER IF EXISTS submission_template_update_trigger ON submission_template;
|
||||
CREATE TRIGGER submission_template_update_trigger BEFORE UPDATE ON submission_template FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
|
||||
</sql>
|
||||
<sql>
|
||||
DROP TRIGGER IF EXISTS submission_template_insert_trigger ON submission_template;
|
||||
CREATE TRIGGER submission_template_insert_trigger BEFORE INSERT ON submission_template FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
|
||||
</sql>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.25.xsd">
|
||||
<include file="trigger_functions.xml" relativeToChangelogFile="true"/>
|
||||
<include file="item.xml" relativeToChangelogFile="true"/>
|
||||
<include file="currency.xml" relativeToChangelogFile="true"/>
|
||||
<include file="user.xml" relativeToChangelogFile="true"/>
|
||||
<include file="opening.xml" relativeToChangelogFile="true"/>
|
||||
<include file="submission_template.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.25.xsd">
|
||||
<changeSet author="Sheldan" id="insert_trigger" dbms="postgresql">
|
||||
<sqlFile encoding="utf8" path="sql/insert_trigger.sql"
|
||||
relativeToChangelogFile="true"
|
||||
splitStatements="false"/>
|
||||
</changeSet>
|
||||
<changeSet author="Sheldan" id="update_trigger" dbms="postgresql">
|
||||
<sqlFile encoding="utf8" path="sql/update_trigger.sql"
|
||||
relativeToChangelogFile="true"
|
||||
splitStatements="false"/>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.25.xsd">
|
||||
|
||||
<changeSet author="Sheldan" id="user-table">
|
||||
<createTable tableName="gw2_user">
|
||||
<column name="id" type="VARCHAR(255)">
|
||||
<constraints nullable="false" primaryKey="true"/>
|
||||
</column>
|
||||
<column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
|
||||
</createTable>
|
||||
<sql>
|
||||
DROP TRIGGER IF EXISTS gw2_user_update_trigger ON gw2_user;
|
||||
CREATE TRIGGER gw2_user_update_trigger BEFORE UPDATE ON gw2_user FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
|
||||
</sql>
|
||||
<sql>
|
||||
DROP TRIGGER IF EXISTS gw2_user_insert_trigger ON gw2_user;
|
||||
CREATE TRIGGER gw2_user_insert_trigger BEFORE INSERT ON gw2_user FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
|
||||
</sql>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.25.xsd">
|
||||
<include file="0.0.1/collection.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
Reference in New Issue
Block a user