How does Spring Boot manage database schema migrations (Flyway vs Hibernate ddl-auto)? स्प्रिंग बूट डेटाबेस स्कीमा माइग्रेशन को कैसे मैनेज करता है (Flyway बनाम Hibernate ddl-auto)?
spring.jpa.hibernate.ddl-auto lets Hibernate generate or update the schema automatically based on entity classes (values like update, create, validate, none), which is convenient for local development but risky in production since it can silently alter or drop columns and offers no versioned history.
Flyway (or Liquibase) manages schema changes as versioned, reviewable SQL migration scripts (e.g. V1__init.sql, V2__add_email_column.sql) that run in order and are tracked in a schema history table, giving predictable, auditable, and rollback-friendly migrations. The recommended production pattern is ddl-auto=validate (or none) paired with Flyway managing the actual schema changes.
# application.properties
spring.jpa.hibernate.ddl-auto=validate
spring.flyway.enabled=true
spring.flyway.locations=classpath:db/migrationspring.jpa.hibernate.ddl-auto, एंटिटी क्लासेज़ के आधार पर Hibernate को स्कीमा स्वचालित रूप से जनरेट या अपडेट करने देता है (update, create, validate, none जैसी वैल्यूज़), जो लोकल डेवलपमेंट के लिए सुविधाजनक है लेकिन प्रोडक्शन में जोखिम भरा है क्योंकि यह चुपचाप कॉलम बदल या हटा सकता है और इसका कोई वर्जन्ड इतिहास नहीं होता।
Flyway (या Liquibase) स्कीमा बदलावों को वर्जन्ड, रिव्यूएबल SQL माइग्रेशन स्क्रिप्ट्स के रूप में मैनेज करता है, जो क्रम में चलते हैं और एक स्कीमा हिस्ट्री टेबल में ट्रैक होते हैं। अनुशंसित प्रोडक्शन पैटर्न है ddl-auto=validate के साथ Flyway को वास्तविक स्कीमा बदलाव मैनेज करने देना।
# application.properties
spring.jpa.hibernate.ddl-auto=validate
spring.flyway.enabled=true
spring.flyway.locations=classpath:db/migrationWas this answer clear?