From d4137290387d118534888a9c4120223ebee1bcc5 Mon Sep 17 00:00:00 2001 From: Johnny Date: Mon, 9 Jun 2025 23:06:32 +0800 Subject: [PATCH] chore: remove seed data --- bin/slash/main.go | 4 +- frontend/web/src/App.tsx | 2 - frontend/web/src/components/DemoBanner.tsx | 27 ------- server/common/version.go | 2 +- server/profile/profile.go | 4 +- store/migrator.go | 45 +---------- store/seed/sqlite/10000__user.sql | 34 -------- store/seed/sqlite/10001__shortcut.sql | 94 ---------------------- store/seed/sqlite/10002__collection.sql | 20 ----- 9 files changed, 6 insertions(+), 226 deletions(-) delete mode 100644 frontend/web/src/components/DemoBanner.tsx delete mode 100644 store/seed/sqlite/10000__user.sql delete mode 100644 store/seed/sqlite/10001__shortcut.sql delete mode 100644 store/seed/sqlite/10002__collection.sql diff --git a/bin/slash/main.go b/bin/slash/main.go index 6640447..33075f7 100644 --- a/bin/slash/main.go +++ b/bin/slash/main.go @@ -89,11 +89,11 @@ var ( ) func init() { - viper.SetDefault("mode", "demo") + viper.SetDefault("mode", "dev") viper.SetDefault("driver", "sqlite") viper.SetDefault("port", 8082) - rootCmd.PersistentFlags().String("mode", "demo", `mode of server, can be "prod" or "dev" or "demo"`) + rootCmd.PersistentFlags().String("mode", "dev", `mode of server, can be "prod" or "dev"`) rootCmd.PersistentFlags().String("addr", "", "address of server") rootCmd.PersistentFlags().Int("port", 8082, "port of server") rootCmd.PersistentFlags().String("data", "", "data directory") diff --git a/frontend/web/src/App.tsx b/frontend/web/src/App.tsx index 721a747..a2b115f 100644 --- a/frontend/web/src/App.tsx +++ b/frontend/web/src/App.tsx @@ -1,7 +1,6 @@ import { useColorScheme } from "@mui/joy"; import { useEffect } from "react"; import { Outlet } from "react-router-dom"; -import DemoBanner from "@/components/DemoBanner"; import { useWorkspaceStore } from "@/stores"; import useNavigateTo from "./hooks/useNavigateTo"; import { FeatureType } from "./stores/workspace"; @@ -72,7 +71,6 @@ function App() { return ( <> - ); diff --git a/frontend/web/src/components/DemoBanner.tsx b/frontend/web/src/components/DemoBanner.tsx deleted file mode 100644 index d7bfada..0000000 --- a/frontend/web/src/components/DemoBanner.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import { useWorkspaceStore } from "@/stores"; -import Icon from "./Icon"; - -const DemoBanner: React.FC = () => { - const workspaceStore = useWorkspaceStore(); - const shouldShow = workspaceStore.profile.mode === "demo"; - - if (!shouldShow) return null; - - return ( -
-
- ✨🔗 Slash - An open source, self-hosted platform for sharing and managing your most frequently used links. - - Install - - -
-
- ); -}; - -export default DemoBanner; diff --git a/server/common/version.go b/server/common/version.go index d8ac471..ae92e1c 100644 --- a/server/common/version.go +++ b/server/common/version.go @@ -15,7 +15,7 @@ var Version = "1.0.0" var DevVersion = "1.0.0" func GetCurrentVersion(mode string) string { - if mode == "dev" || mode == "demo" { + if mode == "dev" { return DevVersion } return Version diff --git a/server/profile/profile.go b/server/profile/profile.go index a7338d1..5684116 100644 --- a/server/profile/profile.go +++ b/server/profile/profile.go @@ -52,8 +52,8 @@ func checkDataDir(dataDir string) (string, error) { } func (p *Profile) Validate() error { - if p.Mode != "demo" && p.Mode != "dev" && p.Mode != "prod" { - p.Mode = "demo" + if p.Mode != "dev" && p.Mode != "prod" { + p.Mode = "dev" } if p.Mode == "prod" && p.Data == "" { diff --git a/store/migrator.go b/store/migrator.go index 097e53d..9c2cb62 100644 --- a/store/migrator.go +++ b/store/migrator.go @@ -22,8 +22,7 @@ import ( //go:embed migration var migrationFS embed.FS -//go:embed seed -var seedFS embed.FS + const ( // MigrateFileNameSplit is the split character between the patch version and the description in the migration file name. @@ -104,11 +103,6 @@ func (s *Store) Migrate(ctx context.Context) error { return errors.Wrapf(err, "failed to upsert migration history with version: %s", schemaVersion) } } - } else if s.profile.Mode == "demo" { - // In demo mode, we should seed the database. - if err := s.seed(ctx); err != nil { - return errors.Wrap(err, "failed to seed") - } } // Manually migrate workspace settings. @@ -171,43 +165,6 @@ func (s *Store) getMigrationBasePath() string { return fmt.Sprintf("migration/%s/%s/", s.profile.Driver, mode) } -func (s *Store) getSeedBasePath() string { - return fmt.Sprintf("seed/%s/", s.profile.Driver) -} - -func (s *Store) seed(ctx context.Context) error { - // Only seed for SQLite. - if s.profile.Driver != "sqlite" { - slog.Warn("seed is only supported for SQLite") - return nil - } - - filenames, err := fs.Glob(seedFS, fmt.Sprintf("%s*.sql", s.getSeedBasePath())) - if err != nil { - return errors.Wrap(err, "failed to read seed files") - } - - // Sort seed files by name. This is important to ensure that seed files are applied in order. - sort.Strings(filenames) - // Start a transaction to apply the seed files. - tx, err := s.driver.GetDB().Begin() - if err != nil { - return errors.Wrap(err, "failed to start transaction") - } - defer tx.Rollback() - // Loop over all seed files and execute them in order. - for _, filename := range filenames { - bytes, err := seedFS.ReadFile(filename) - if err != nil { - return errors.Wrapf(err, "failed to read seed file, filename=%s", filename) - } - if err := s.execute(ctx, tx, string(bytes)); err != nil { - return errors.Wrapf(err, "seed error: %s", filename) - } - } - return tx.Commit() -} - func (s *Store) GetCurrentSchemaVersion() (string, error) { currentVersion := common.GetCurrentVersion(s.profile.Mode) minorVersion := common.GetMinorVersion(currentVersion) diff --git a/store/seed/sqlite/10000__user.sql b/store/seed/sqlite/10000__user.sql deleted file mode 100644 index 125db86..0000000 --- a/store/seed/sqlite/10000__user.sql +++ /dev/null @@ -1,34 +0,0 @@ -INSERT INTO - user ( - `id`, - `role`, - `email`, - `nickname`, - `password_hash` - ) -VALUES - ( - 101, - 'ADMIN', - 'slash@yourselfhosted.com', - 'Slasher', - '$2a$10$H8HBWGcG/hoePhFy5SiNKOHxMD6omIpyEEWbl/fIorFC814bXW.Ua' - ); - -INSERT INTO - user ( - `id`, - `role`, - `email`, - `nickname`, - `password_hash` - ) -VALUES - ( - 102, - 'USER', - 'steven@yourselfhosted.com', - 'Steven', - -- raw password: secret - '$2a$14$ajq8Q7fbtFRQvXpdCq7Jcuy.Rx1h/L4J60Otx.gyNLbAYctGMJ9tK' - ); diff --git a/store/seed/sqlite/10001__shortcut.sql b/store/seed/sqlite/10001__shortcut.sql deleted file mode 100644 index 0056e61..0000000 --- a/store/seed/sqlite/10001__shortcut.sql +++ /dev/null @@ -1,94 +0,0 @@ -INSERT INTO - shortcut ( - `id`, - `creator_id`, - `name`, - `link`, - `visibility` - ) -VALUES - ( - 1, - 101, - 'discord', - 'https://discord.gg/QZqUuUAhDV', - 'PUBLIC' - ); - -INSERT INTO - shortcut ( - `id`, - `creator_id`, - `name`, - `link`, - `visibility`, - `tag`, - `og_metadata` - ) -VALUES - ( - 2, - 101, - 'ai-infra', - 'https://star-history.com/blog/open-source-ai-infra-projects', - 'PUBLIC', - 'star-history ai', - '{"title":"Open Source AI Infra for Your Next Project","description":"Some open-source infra projects that can be directly used for your next project. 💡","image":"https://star-history.com/blog/assets/open-source-ai-infra-projects/banner.webp"}' - ); - -INSERT INTO - shortcut ( - `id`, - `creator_id`, - `name`, - `link`, - `visibility`, - `tag`, - `og_metadata` - ) -VALUES - ( - 3, - 101, - 'schema-change', - 'https://www.bytebase.com/blog/how-to-handle-database-schema-change/#what-is-a-database-schema-change', - 'PUBLIC', - 'database article👍', - '{"title":"How to Handle Database Migration / Schema Change?","description":"A database schema is the structure of a database, which describes the relationships between the different tables and fields in the database. A database schema change, also known as schema migration, or simply migration refers to any alteration to this structure, such as adding a new table, modifying the data type of a field, or changing the relationships between tables.","image":"https://www.bytebase.com/_next/image/?url=%2Fcontent%2Fblog%2Fhow-to-handle-database-schema-change%2Fchange.webp\u0026w=2048\u0026q=75"}' - ); - -INSERT INTO - shortcut ( - `id`, - `creator_id`, - `name`, - `link`, - `tag`, - `visibility` - ) -VALUES - ( - 4, - 101, - 'sqlchat', - 'https://www.sqlchat.ai', - 'ai chatbot sql', - 'WORKSPACE' - ); - -INSERT INTO - shortcut ( - `id`, - `creator_id`, - `name`, - `link`, - `visibility` - ) -VALUES - ( - 5, - 102, - 'stevenlgtm', - 'https://github.com/boojack', - 'PUBLIC' - ); diff --git a/store/seed/sqlite/10002__collection.sql b/store/seed/sqlite/10002__collection.sql deleted file mode 100644 index 9e21a2e..0000000 --- a/store/seed/sqlite/10002__collection.sql +++ /dev/null @@ -1,20 +0,0 @@ -INSERT INTO - collection ( - `id`, - `creator_id`, - `name`, - `title`, - `description`, - `visibility`, - `shortcut_ids` - ) -VALUES - ( - 1, - 101, - 'minecraft', - 'Minecraft', - 'My daily thoughts and ideas', - 'PUBLIC', - '1,2,3,4,5' - );