chore: remove seed data

This commit is contained in:
Johnny
2025-06-09 23:06:32 +08:00
parent ba33336dc4
commit d413729038
9 changed files with 6 additions and 226 deletions
+2 -2
View File
@@ -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")
-2
View File
@@ -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 (
<>
<DemoBanner />
<Outlet />
</>
);
@@ -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 (
<div className="z-10 relative flex flex-row items-center justify-center w-full py-2 text-sm sm:text-lg font-medium dark:text-gray-300 bg-white dark:bg-zinc-700 shadow">
<div className="w-full max-w-8xl px-4 md:px-12 flex flex-row justify-between items-center gap-x-3">
<span>🔗 Slash - An open source, self-hosted platform for sharing and managing your most frequently used links.</span>
<a
className="shadow flex flex-row justify-center items-center px-2 py-1 rounded-md text-sm sm:text-base text-white bg-blue-600 hover:bg-blue-700"
href="https://github.com/yourselfhosted/slash#deploy-with-docker-in-seconds"
target="_blank"
>
Install
<Icon.ExternalLink className="w-4 h-auto ml-1" />
</a>
</div>
</div>
);
};
export default DemoBanner;
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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 == "" {
+1 -44
View File
@@ -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)
-34
View File
@@ -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'
);
-94
View File
@@ -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'
);
-20
View File
@@ -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'
);