Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package naughty.tuzamate.domain.stock.entity;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.*;
import lombok.*;

@Entity
Expand All @@ -14,7 +11,13 @@
public class KrxStockInfo {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@GeneratedValue(strategy = GenerationType.SEQUENCE,
generator = "krx_stock_info_seq")
@SequenceGenerator(
name = "krx_stock_info_seq",
sequenceName = "krx_stock_info_seq",
allocationSize = 50 // 시퀀스 한 번에 50개 id 확보
)
Comment on lines +14 to +20
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify DB dialect and add DB migrations for the sequence (prod/staging).

SEQUENCE requires DB support and presence of the named sequence. If you’re on MySQL, this will break; if Postgres/Oracle, add migrations to create and initialize the sequence(s) accordingly. Also ensure start value ≥ max(id)+1 to avoid PK collisions on existing tables.

Run the following to verify DB dialect and presence of sequence migrations:

If you’re on Postgres, a Flyway SQL example:

-- Vxxx__create_stock_sequences.sql
CREATE SEQUENCE IF NOT EXISTS krx_stock_info_seq INCREMENT BY 50;
SELECT setval('krx_stock_info_seq', GREATEST((SELECT COALESCE(MAX(id),0) FROM krx_stock_info), 1), true);

CREATE SEQUENCE IF NOT EXISTS nasdaq_stock_info_seq INCREMENT BY 50;
SELECT setval('nasdaq_stock_info_seq', GREATEST((SELECT COALESCE(MAX(id),0) FROM nasdaq_stock_info), 1), true);

If on Oracle:

BEGIN
  EXECUTE IMMEDIATE 'CREATE SEQUENCE krx_stock_info_seq INCREMENT BY 50 START WITH 1';
EXCEPTION WHEN OTHERS THEN IF SQLCODE != -955 THEN RAISE; END IF; END;
/
BEGIN
  EXECUTE IMMEDIATE 'CREATE SEQUENCE nasdaq_stock_info_seq INCREMENT BY 50 START WITH 1';
EXCEPTION WHEN OTHERS THEN IF SQLCODE != -955 THEN RAISE; END IF; END;
/

If on MySQL/MariaDB: SEQUENCE is not supported in MySQL (and differs in MariaDB). You’ll need IDENTITY or TABLE generator there. I can generate the required DB-specific migrations or revert strategy if needed.


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Checking DB dialect config (application.*) =="
fd -a 'application.*' src/main/resources | xargs -r -I{} sh -c 'echo "-- {} --"; rg -n -C2 -e "spring.datasource.url|spring.jpa.database-platform|hibernate.dialect" "{}" || true'

echo
echo "== Stock entities using @GeneratedValue strategies =="
rg -nP -C3 --glob 'src/main/java/**/domain/stock/entity/**' '@GeneratedValue\s*\(.*?GenerationType\.\w+'

echo
echo "== Migration scripts referencing the new sequences =="
rg -n -C2 -e 'create sequence|alter sequence|setval|krx_stock_info_seq|nasdaq_stock_info_seq' --hidden

Length of output: 415


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Repo top-level =="
ls -la

echo
echo "== Find application.* files =="
fd -a 'application.*' || true

echo
echo "== Search for Spring DB / Hibernate config in repository =="
rg -nS --hidden -e 'spring\.datasource|spring\.jpa|hibernate\.dialect|spring\.datasource\.url|spring\.jpa\.database-platform' || true

echo
echo "== Search for GenerationType.SEQUENCE / @SequenceGenerator / @GeneratedValue usages =="
rg -nP --hidden -C3 -e 'GenerationType\.SEQUENCE|@SequenceGenerator|@GeneratedValue' || true

echo
echo "== Search for migration SQL referencing sequences =="
rg -nS --hidden -e 'krx_stock_info_seq|create sequence|CREATE SEQUENCE|setval|alter sequence' || true

echo
echo "== Locate KrxStockInfo.java and show its top 200 lines if present =="
file_path=$(rg -n --hidden -S -g '!**/target/**' 'class\s+KrxStockInfo' | sed -n '1s/:.*//p' || true)
if [ -n "$file_path" ]; then
  echo "-- $file_path --"
  sed -n '1,200p' "$file_path"
else
  echo "KrxStockInfo.java not found"
fi

Length of output: 11556


Add DB migrations for SEQUENCE-based IDs or switch to a DB-compatible strategy

Quick summary: I verified the repo — two entities use GenerationType.SEQUENCE but there are no DB dialect/config entries or migration scripts creating those sequences. This will fail on MySQL (which lacks SEQUENCE) and will still require explicit sequence creation on Postgres/Oracle to avoid PK collisions.

Files needing attention:

  • src/main/java/naughty/tuzamate/domain/stock/entity/KrxStockInfo.java — generator "krx_stock_info_seq"
  • src/main/java/naughty/tuzamate/domain/stock/entity/NasdaqStockInfo.java — generator "nasdaq_stock_info_seq"

Verification notes:

  • No occurrences of spring.datasource / spring.jpa / hibernate.dialect were found in the repo (no explicit DB dialect/config detected).
  • No migration SQL referencing krx_stock_info_seq / nasdaq_stock_info_seq (CREATE SEQUENCE / setval / ALTER SEQUENCE) detected.

Actionable fixes (pick one):

  • If you use Postgres/Oracle: add migrations to create the sequences and set their current values >= MAX(id)+1. Example Flyway SQL for Postgres:
    -- Vxxx__create_stock_sequences.sql
    CREATE SEQUENCE IF NOT EXISTS krx_stock_info_seq INCREMENT BY 50;
    SELECT setval('krx_stock_info_seq', GREATEST((SELECT COALESCE(MAX(id),0) FROM krx_stock_info)+1, 1), true);
    CREATE SEQUENCE IF NOT EXISTS nasdaq_stock_info_seq INCREMENT BY 50;
    SELECT setval('nasdaq_stock_info_seq', GREATEST((SELECT COALESCE(MAX(id),0) FROM nasdaq_stock_info)+1, 1), true);
  • If you use MySQL/MariaDB: SEQUENCE is unsupported — change entities to GenerationType.IDENTITY (or use a TABLE generator / application-side id allocation) instead.
  • Ensure allocationSize (50) matches the sequence INCREMENT BY and that the migration start value prevents PK collisions.

Please add the migrations (or change the generation strategy) and ensure they are applied in prod/staging.

🤖 Prompt for AI Agents
In src/main/java/naughty/tuzamate/domain/stock/entity/KrxStockInfo.java (lines
~14-20) and
src/main/java/naughty/tuzamate/domain/stock/entity/NasdaqStockInfo.java, the
entities use GenerationType.SEQUENCE with named generators ("krx_stock_info_seq"
/ "nasdaq_stock_info_seq") but the repo has no DB dialect config or migration
scripts to create those sequences; either add DB migrations for your chosen DB
(e.g., Flyway/V1__create_stock_sequences.sql that creates the two sequences with
INCREMENT BY matching allocationSize and sets their start values >= MAX(id)+1)
if using Postgres/Oracle, or change the entities to a DB-compatible strategy
such as GenerationType.IDENTITY (or TABLE generator/application id allocation)
if using MySQL/MariaDB; also ensure allocationSize (50) matches the sequence
INCREMENT BY in the migration to avoid PK collisions and apply these migrations
in prod/staging.

private Long id;

private String stckShrnIscd; // 주식 단축 종목코드
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package naughty.tuzamate.domain.stock.entity;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.*;
import lombok.*;

@Entity
Expand All @@ -14,7 +11,13 @@
public class NasdaqStockInfo {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@GeneratedValue(strategy = GenerationType.SEQUENCE,
generator = "nasdaq_stock_info_seq")
@SequenceGenerator(
name = "nasdaq_stock_info_seq",
sequenceName = "nasdaq_stock_info_seq",
allocationSize = 50
)
private Long id;

private String code;
Expand Down
Loading